To install Maven on your system, follow these steps:
Step 1: Check Prerequisites
- Before installing Maven, make sure you have the following prerequisites installed on your system:
- Java Development Kit (JDK): Maven requires Java to be installed on your system. You can download and install the latest JDK from the Oracle website or adopt OpenJDK.
Step 2: Download Maven
- Go to the Apache Maven website: https://maven.apache.org/download.cgi
- Under "Files," download the latest binary zip archive of Maven (e.g., apache-maven-3.x.x-bin.zip). Make sure to choose the binary version, not the source version.
Step 3: Extract the Archive
- Once the download is complete, extract the contents of the downloaded zip archive to a directory of your choice. For example, you can extract it to C:\Program Files (on Windows) or /opt (on Linux).
Step 4: Set Environment Variables (Optional)
- (Windows Only) Set the M2_HOME environment variable to the directory where Maven is installed. For example, if you extracted Maven to C:\Program Files\apache-maven-3.x.x, set M2_HOME to that path.
- (Windows Only) Add %M2_HOME%\bin to the PATH environment variable to make Maven commands accessible from the command prompt.
- (Linux Only) Set the M2_HOME environment variable and add the bin directory to the PATH in the appropriate shell configuration file (e.g., .bashrc, .bash_profile, or .zshrc). For example:
export M2_HOME=/opt/apache-maven-3.x.x
export PATH=$PATH:$M2_HOME/bin
Step 5: Verify Installation
- Open a new terminal or command prompt.
- Run the following command to check if Maven is installed and configured correctly:
mvn --version
- This will display the installed Maven version and other relevant information.
- If you see the Maven version and other details in the output, it means Maven is installed successfully.
Congratulations! You have successfully installed Apache Maven on your system. You can now use Maven to manage your Java projects, handle dependencies, and perform various build tasks.
Comments
Post a Comment