Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

install
maven
windows
linux
macos

How to install Maven in Windows and Linux/Unix

Educative Answers Team

Maven is a command-line tool for building Java applications; it is written in Java and is used for building JVM programs. Therefore, it is necessary that Java is installed into the system prior to installing and using Maven.

It is necessary that the commands from the Java JDK are in the PATH environment variable.

Installing Maven on windows

To install Maven on windows:

  • Visit the Apache Maven site, download the Maven zip file of the latest version, and unzip the file to the folder that you want to use Maven in.

  • Add both M2_HOME and MAVEN_HOME variables to the Windows environment variables (using system properties), and point them to your Maven folder.

  • Update the PATH variable by appending the Maven bin folder – %M2_HOME%\bin. This way, Maven’s commands can be run anywhere.

To check whether or not the above steps have been completed successfully, run the following command in the command prompt:

mvn -version

The command should display the Maven version, the Java version, and the operating system information.

Installing Maven on Linux/Unix

To install Maven on Linux/Unix:

  • Visit the Apache Maven site, download the Maven binary tar.gz file of the latest version, and ​extract the archive to the folder you want to use Maven in.

  • Open the terminal and run the following commands to set the environment variables; for example, if apache-maven-3.3.9-bin.tar.gz file was downloaded, the commands would be:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m

The M2_Home path will have to correspond with the location of the extracted Maven files.

  • Append the M2 variable to the system path by running the following command:
export PATH=$M2:$PATH

To check whether or not the above steps have been completed successfully, run the following command in the terminal:

mvn -version

The command should display the Maven and Java versions installed on the system.

RELATED TAGS

install
maven
windows
linux
macos
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring