Apache Maven is a build automation tool widely used for Java projects. It aids in dependency management, project building, and project documentation. This article provides detailed instructions for installing Maven on Windows, macOS, and Linux operating systems, based on official documentation and best practices.
Installation on Windows
The installation process on Windows involves downloading the Maven archive, extracting its contents, and configuring system environment variables.
Step 1: Download and Extract the Maven Zip File
Users should first download the Maven zip file. Specifically, the documentation references apache-maven-3.8.4-bin.zip as an example. After downloading, the zip file must be extracted. The documentation recommends extracting the file to a location within the Windows drive, such as the Program Files folder. Upon extraction, a folder containing the Maven files will be created.
Step 2: Configure the MAVEN_HOME System Variable
To enable Maven to function correctly, a system environment variable named MAVEN_HOME must be created. This variable should point to the directory where Maven was extracted.
- Access the System Environment Variables editor via the Start Menu by searching for “Edit the system environment variables”.
- In the System Properties window, click the “Environment Variables…” button.
- Under the “User variables” section, click “New”.
- Enter a variable name (e.g.,
MAVEN_HOME) and paste the full path to the extracted Maven folder into the “Variable value” field. - Click “OK” to save the new variable.
Step 3: Add the MAVEN_HOME Directory to the PATH Variable
The PATH environment variable must be modified to include the Maven bin directory. This allows users to execute Maven commands from any location in the command prompt.
- In the “System variables” section of the Environment Variables window, locate the
Pathvariable and select it. - Click “Edit”.
- Click “New” and add
%MAVEN_HOME%\binto the list. - Click “OK” on all open windows to save the changes.
Installation on macOS and Linux
The installation process on macOS and Linux involves downloading the Maven archive, extracting it to a suitable location, and configuring the PATH environment variable. The documentation suggests /opt/maven as a potential installation directory.
Step 1: Download the Maven Archive Users should download the Maven archive from the official Apache Maven website, selecting the binary zip or tar.gz archive appropriate for their operating system.
Step 2: Extract the Archive
After downloading, the archive must be extracted to a desired location. The documentation provides an example using the command tar -xvf apache-maven-<version>-bin.zip -C /opt/maven.
Step 3: Configure Environment Variables
The PATH environment variable must be updated to include the Maven bin directory. This can be achieved by adding the following lines to the .bash_profile or .bashrc file:
bash
export M2_HOME=/opt/maven/apache-maven-<version>
export PATH=$M2_HOME/bin:$PATH
source ~/.bash_profile
The documentation notes that these instructions assume the use of the bash shell.
Upgrading a Maven Installation
The documentation details procedures for upgrading existing Maven installations. On Linux, BSD, or macOS, upgrading involves installing the newer version alongside the existing version and updating a symbolic link. For example, if upgrading from version 3.2.5 to a future version, the following commands can be used:
bash
$ ln -s apache-maven-3.2.5 maven
$ export PATH=/opt/maven/bin:${PATH}
On Windows, upgrading involves unpacking the new Maven version to a new directory (e.g., c:\Program Files\maven-3.future) and updating the M2_HOME variable.
Uninstalling Maven
Uninstalling Maven is a straightforward process that involves deleting the Maven installation directory and removing the associated environment variables. The documentation also recommends deleting the ~/.m2 directory, which contains the local repository.
Verifying the Installation
After installation, it is essential to verify that Maven is installed correctly. This can be done by checking the Maven version from the command line. The documentation does not provide the specific command, but it implies that the mvn -version command should work if the installation and environment variables are configured correctly.
Prerequisites and Requirements
Maven requires a Java Development Kit (JDK) to function. The documentation specifies that Maven currently requires Java 7 or higher, recommending the most recent stable JDK. The documentation also notes that while there are no official minimum memory requirements, a JDK is necessary. A minimum of 500 MB of disk space is recommended for the local cache of dependencies.
Important Considerations
The documentation highlights the importance of using the latest version of Maven 3 and avoiding Maven 2, as Maven 2 is no longer maintained. It also emphasizes the need to copy any customizations to the global settings.xml file from the previous Maven installation to the new installation’s conf directory during an upgrade.
Getting Help
The documentation directs users to the Maven website for additional help and resources.
Conclusion
Installing Apache Maven involves downloading the appropriate archive for your operating system, extracting it to a suitable location, and configuring the necessary environment variables. Following these steps ensures that Maven is correctly installed and can be used to manage Java projects effectively. Proper verification of the installation is crucial to confirm that Maven is functioning as expected. The documentation stresses the importance of using a compatible JDK and staying up-to-date with the latest Maven releases.

