Create a directory named maven under /opt
# mkdir /opt/maven
Download maven from apache maven link in /opt/maven folder
# wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
Note : Always download from binary option. I had to spend hours to fix the issue after installing from source due to
following error while mvn –version command
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Extract the tar file and install maven
# sudo tar -xvzf apache-maven-3.6.2-src.tar.gz
Set the /root/.bash_profile file as follow to set maven path
# User specific environment and startup programs
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64
M2_HOME=/opt/maven/apache-maven-3.6.2
M2=$M2_HOME/bin
PATH=$PATH:$JAVA_HOME:$M2_HOME:$M2_HOME/bin
Install plugin maven integration using option without restart
Configure maven path under maven configuration
Manage Jenkins >> Global Tool Configration >> Maven
Provide Maven path as /opt/maven/apache-maven-3.6.2
You need to verify maven is successfully installed using mvn –version