Skip to content

Install Maven

Abstract

Due to a complex multi-modules tree structure, a recent version of maven is recommended, in particular maven >= 3.6.1.

Manual setup

Linux

Download maven and install it:

wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
sudo ln -s /opt/apache-maven-3.6.3 /opt/maven

Update your environment:

sudo vim /etc/profile.d/maven.sh

Paste the following configuration:

/etc/profile.d/maven.sh

# export JAVA_HOME=/usr/lib/jvm/default-java (only if not already set by Jenv)
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save and close the file. This script will be sourced at shell startup.

Make the script executable with chmod:

sudo chmod +x /etc/profile.d/maven.sh

Finally load the environment variables using the source command:

source /etc/profile.d/maven.sh

Verify the installation:

To validate that Maven is installed properly use the mvn -version command which will print the Maven version:

mvn -version