I am trying to install maven in linux machine using the following command:
sudo apt install maven
But this command installs the maven version 3.6.0, whereas the latest version for maven in the apache maven web-site is 3.8.1. Any suggestions on how to install maven 3.8.1 via apt install command or any else ways?
This is a small guide to install maven on ubuntu 20.04 LTS. Jul 28, 2021
Download maven from https://maven.apache.org/download.cgi click the link apache-maven-3.8.1-bin.tar.gz.
Extract the files in your downloads folder.
cd Downloads
sudo tar xzvf apache-maven-3.8.1-bin.tar.gz -C/opt/
In a terminal window enter the following.
nano .profile
Edit the file and add the following text at the bottom of the page.
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export JAVA_HOME
MAVEN_HOME=/opt/apache-maven-3.8.1
export MAVEN_HOME
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
export PATH
Now press ctrl + O to save the file, and ctrl + X to close the file.
Back in the terminal run the script with.
. .profile
Check the version of java and maven with the commands.
`java --version`
`mvn --version`
Now you should see the proper version of Maven installed.
If you open a new terminal window and the installation seems ineffective: LOGOUT AND LOGIN!!!**
Following command helped me.
Remove current version:
sudo apt-get purge maven
Download the latest version:
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
tar -xvf apache-maven-3.8.6-bin.tar.gz
Installation:
sudo cp -r apache-maven-3.8.6 /opt
export PATH=/opt/apache-maven-3.8.6/bin:$PATH
echo -e "\nPATH=\"/opt/apache-maven-3.8.6/bin:\$PATH\"" >> ~/.profile
Script
#!/bin/sh
version=$1
if [ -z $version ] ; then echo "specify version" ; exit 1 ; fi
#Remove old maven
sudo apt-get purge maven -y
url="https://dlcdn.apache.org/maven/maven-3/${version}/binaries/apache-maven-${version}-bin.tar.gz"
echo $url
wget $url
sleep .4
tarFile="apache-maven-${version}-bin.tar.gz"
echo $tarFile
sudo tar -xvf $tarFile -C /opt/
export PATH=/opt/apache-maven-${version}/bin:$PATH
echo -e "\nPATH=\"/opt/apache-maven-${version}/bin:\$PATH\"" >> ~/.profile
Pass the 1st argument as the maven version.
Example: ./install.sh 3.8.7
Note: Make sure Java is installed before following the above steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With