How to Install Maven on Windows, Linux, and Mac
Maven is a command-line tool used for building and managing Java-based applications. We can get an archive containing all the files needed to set up Maven. There is no need for an installer. We need to set up the prerequisites and configure our environment to run Maven.
Maven is written using Java, so make sure that your system has Java installed in it.
Run the following command to make sure that Java is installed on your system. Install the latest JDK and add the JAVA_HOME environment variable, if Java is not installed.
Installing Maven On Windows
- Unzip the contents where you want to store the Maven files.
- Next, add the M2_HOME and MAVEN_HOME variables to the Windows environment variables by using the system properties. Point them to where you stored your Maven files.
- The last step includes updating the PATH variable to run Maven commands from anywhere. We need to append the Maven bin folder - %M2_HOME%\bin - to the path variable.
- We can confirm whether Maven was successfully set up or not by running the following command to check its version.
Installing Maven On Linux
- To install Maven on Linux, head over to the official Apache Maven Project website(https://maven.apache.org/download.cgi) and download the binary tar.gz file. Extract the archive to the folder where you want to use Maven.
- Next, open the terminal and use the following commands to set the environment variables. Note that the M2_Home path will have to correspond with the location of the extracted Maven files.
export MAVEN_OPTS=-Xms256m -Xmx512m
- Next, we need to append the M2 variable to the path.
- To confirm whether Maven was successfully added or not, use the following command.
Installing Maven on Ubuntu
We can easily install Maven on Ubuntu by using the apt command.
- First, update the package index by running the following command.
sudo apt update
- Next, install Maven by using the following apt command.
sudo apt install maven
- The above command can take a few minutes to download and install Maven. Once done, we can verify the installation by using the following command.
Installing Maven on Mac OS X
- Head over to the official Apache Maven Project website(https://maven.apache.org/download.cgi) and download the latest Maven binary tar.gz file. Extract it to the location where you want Maven to live.
- Next, we need to set the environment variables. We need to add the Maven bin directory to the Path variable. Open .bash_profile in your text editor and add the following commands to it.
- Use the source .bash_profile command to apply the changes. To verify the installation, run the following mvn command.
If you have Homebrew installed, then you can simply run the following command to install Maven.
brew install maven
To confirm the installation, run the mvn version command.
Maven is a popular build and dependency management tool for Java applications. Installing and setting up Maven is not very complicated. We can download the necessary files from the Apache Maven project website. In this tutorial, we learned how to install Maven on different operating systems.