Maven is written in Java. For this you need to install the Java JDK. Once Java is installed, you must ensure that the commands from the Java JDK are in your PATH environment variable.
Verify that Java was successfully installed by running the following command:
$ java -version
Installing Maven on Windows
- Make sure JDK is installed, and
JAVA_HOMEenvironment variable is configured.
- Visit Maven official website, download the Maven zip file, for example :
- Unzip it to a folder. I are using
- Add MAVEN_HOME system variable
In System Properties dialog, select
Advanced tab and clicks on the
Environment Variables... button.
In “Environment variables” dialog,
System variables, Clicks on the
New... button and add a
MAVEN_HOME variable and point it to
- In system variables, find
PATH, clicks on the
Edit...button. In “Edit environment variable” dialog, clicks on the
Newbutton and add this
Installing Maven on macOS
With Mac OS X, Maven is not installed by default anymore. Different options are then possible:
- Using Homebrew:
# will install latest Maven $ brew install maven # will install Maven 3.0 if needed $ brew install maven30
- Using Macports:
# will install latest Maven $ sudo port install maven # will Install Maven 3.0 $ sudo port install maven3
- Installing by hand: Download Maven from its homepage
Follow the installation instructions:
- Move to home folder and create a new folder for maven artifacts:
cd ~ && mkdirDevelopment
- Extract the distribution archive, i.e.
apache-maven-3.6.3-bin.tar.gzto the directory you wish to install Maven 3.6.3. The subdirectory
apache-maven-3.6.3will be created from the archive.
- Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g.
export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
- Make sure that JAVA_HOME is set to the location of your JDK, e.g.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)and that
$JAVA_HOME/binis in your
PATHenvironment variable (although that might not be necessary with the latest Mac OS X versions and the Oracle JDK).
- Add extracted
- uncompress it (
apache-maven-3.6.3-bin.zip) and added
maven pathinto environment variable
PATH. Normally is edit and add:
into your startup script(
7. Create a symbolic link of the uncompressed file:
ln -s ~/Development/apache-maven-3.6.3 /usr/local/apache-maven
8. Verify that it is correctly installed by typing the
mvn -version command:
$ mvn -version
The output should look something like this:
Installing Maven on Linux
Installing Apache Maven on Debian or Ubuntu with Apt
# First, update the package index: $ sudo apt update # Install Maven by running the following command: $ sudo apt install maven # Verify the installation by typing: $ mvn -version
Installing Maven on CentOS 7 using
yum is a simple, straightforward process.
$ sudo yum install maven
- Installing by hand:
$ cd ~ && mkdir installed-packages # Go to https://maven.apache.org/download.cgi and wget the latest artifact: # If you don't have wget installed: sudo yum install -y wget $ cd ~/installed-packages wget http://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz # Uncompress the downloaded file: $ tar -xvf apache-maven-3.6.3-bin.tar.gz # Create a symbolic link of the uncompressed file: $ ln -s ~/installed-packages/apache-maven-3.5.0 /usr/local/apache-maven # Edit ~/.bash_profile (This is where environment variables are commonly stored): $ vi ~/.bash_profile # Add the variable: MAVEN_HOME=/usr/local/apache-maven (do this before PATH variable is defined) # (For those who don't know vi tool: Press i key to enable insert mode) # Go to the end of the line where PATH variable is defined and append the following: :$MAVEN_HOME:$MAVEN_HOME/bin # Save changes # (For those who don't know vi tool: Press esc key to exit insert mode and :wq! to save and quit file) # Reload environment variables: $ source ~/.bash_profile # Confirm that maven command now works properly: $ mvn --help
Verify the installation
$ mvn -version