Home Hibernate How to Install Maven on windows / Linux / Mac

How to Install Maven on windows / Linux / Mac

A step by step guide on how to install Maven on Windows 10 / Linux Ubuntu / Mac operating systems manually and from Command line.

Choose a platform and proceed to the installation steps :

Make sure Java JDK installation 1.7 or higher OR GraalVM for Java 8 or higher installed in your system and already set JAVA_HOME system path. In Any system following are the basic steps to setup Maven.

  1. Get appropriate Maven binary distribution from official Maven site.
  2. Create an MAVEN_HOME System Variable.
  3. %MAVEN_HOME%\bin; to your System Path.
Install Maven on Windows 10
Install Maven on Linux
Install Maven on Mac

1. Manual Installation on Windows

To install Maven on Windows, download binary zip archive from apache-maven-3.xxx-bin.zip, extract it in your local system.

2. Add MAVEN_HOME System Variable

To add MAVEN_HOME System variable on windows :

1. Press on Windows key -> type Environment -> Select “Edit the system environment variables

2. Select Environment Variables… button.

3. Click on New… button and add MAVEN_HOME and your extracted path. Ex: Z:\D\maven\apache-maven-3.6.3

3. Add %MAVEN_HOME%\bin to PATH

In System variables, select Path -> click on Edit… option -> In Edit environment variables window click New -> include %MAVEN_HOME%\bin

That’s all, manually setting up Maven on Windows is done. Let’s have a look into how to setup MAVEN_HOME and bin from command line.

4. Setup MAVEN_HOME System variable and update PATH from Command line on Windows

1. To set System variables from command line, open cmd command prompt as administrator and issue following command.

C:\Windows\system32>setx /M MAVEN_HOME "Z:\D\maven\apache-maven-3.6.3"

SUCCESS: Specified value was saved.

2. Update %MAVEN_HOME%\bin from command line.

$ setx /M PATH "%MAVEN_HOME%\bin;%PATH%"

5. Test Maven Setup on Windows

To test maven installation successful, just try mvn -version from command prompt, you will get similar following results.

$ mvn -version

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: Z:\D\maven\apache-maven-3.6.3\bin\..
Java version: 11.0.7, vendor: GraalVM Community, runtime: Z:\D\graalvm\graalvm-ce-java11-20.1.0
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

1. Install Maven on Ubuntu

1.1. There are several ways you can install Maven on Linux. Run command sudo apt install maven to install Maven along with Java on Linux Ubuntu, it will get the latest maven distribution.

$ sudo apt install maven

1.2. Testing Installation :

$ mvn -version

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-40-generic", arch: "amd64", family: "unix"

2. Alternate way to install Maven on Linux Ubuntu

Make sure already Java JDK or GraalVM setup done on your Linux Machine.

2.1. Download binary tar archive from apache-maven-3.xxx-bin.tar.gz, extract it in your local system.

$ wget -P /home/ubuntuadmin/Documents/ "https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz"
$ cd /home/ubuntuadmin/Documents/
$ tar xz -f apache-maven-3.6.3-bin.tar.gz

2.2. Create MAVEN_HOME variable and update $MAVEN_HOME/bin to PATH. To update them on Linux Ubuntu run following commands.

$ sudo nano ~/.bashrc     OR  sudo gedit ~/.bashrc  (on desktop version)

Include the following lines at the end to the .bashrc file.

MAVEN_HOME="/home/ubuntuadmin/Documents/apache-maven-3.6.3"
PATH="$MAVEN_HOME/bin":$PATH

2.3. Test the Maven Installation on Ubuntu

$ mvn -version

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/ubuntuadmin/Documents/apache-maven-3.6.3
Java version: 11.0.7, vendor: GraalVM Community, runtime: /home/ubuntuadmin/Documents/graalvm-ce-java11-20.1.0
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-40-generic", arch: "amd64", family: "unix"

1. Download Maven and extract in Local Mac

Make sure already Java JDK or GraalVM setup done on your Mac Machine. Download binary tar archive from apache-maven-3.xxx-bin.tar.gz, extract it in your local system. In my case binary downloaded /Downloads/apache-maven-3.6.3-bin.tar.gz . Extract the archive file to specific location.

$ tar -xvf ~/Downloads/apache-maven-3.6.3-bin.tar.gz -C ~/Downloads/

Move to specific folder.

$ sudo mv ~/Downloads/apache-maven-3.6.3 /Library/apache-maven-3.6.3

2. Set MAVEN_HOME and $MAVEN_HOME/bin to PATH on Mac

Open .bash_profile using TextEdit or nano and include MAVEN_HOME and $MAVEN_HOME/bin to PATH.

sudo open -a TextEdit .bash_profile      OR      sudo nano .bash_profile

 Add the following lines and save .bash_profile file.

export MAVEN_HOME=/Library/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH

 Refresh the settings from .bash_profile.

$ source .bash_profile

3. Test Maven Installation on Mac

Maven setup is done on Mac OS, to test the setup run mvn -version command.

$ mvn -version

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Library/apache-maven-3.6.3
Java version: 11.0.7, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.1.0/Contents/Home
Default locale: en_MY, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"

Conclusion

In this guide we have seen how to install Maven on Windows 10 / Linux Ubuntu / Mac operating systems manually and from Command line. Did it work for you or any issue comment below.

References

  1. Apache Maven
  2. Install GraalVM on Windows / Linux / Mac

Satish Varma
Satish Varmahttps://javabydeveloper.com
Satish is post graduated in master of computer applications and experienced software engineer with focus on Spring, JPA, REST, TDD and web development. Follow him on LinkedIn or Twitter or Facebook

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay in Touch

Categories