Apache Maven —installing it

Daniel Maioni
2 min readMar 23, 2023

--

Maven is a build automation tool for java projects and other languages (C#, Ruby, Scala, others).

To work with maven projects, we have to install it first.

Check it out the last maven binaries at https://dlcdn.apache.org/maven/

Download it, and extract into your optional software folder or /opt/maven (if opt is not available, create it with sudo mkdir /opt) :

sudo apt update
sudo mkdir /opt/maven
wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp
sudo tar xf /tmp/apache-maven-3.9.6-bin.tar.gz -C /opt
ls /opt/apache-maven-3.9.6/

Create a symbolic link to maven with the command ln adding the parameters s (symbolic) f (force) and n (no-dereference):

sudo ln -sf /opt/apache-maven-3.9.6 /opt/maven  
ls -ld /opt/maven
which mvn

Let’s configure the environment variables, make sure that you already have java installed otherwise click here to know how to do it first:

sudo echo "export JAVA_HOME=/usr/lib/jvm/java-in-use" >> ~/.bashrc
sudo echo "export M2_HOME=/opt/maven" >> ~/.bashrc
sudo echo "export MAVEN_HOME=/opt/maven" >> ~/.bashrc
sudo echo "export PATH=${M2_HOME}/bin:${PATH}" >> ~/.bashrc
source ~/.bashrc

geAsudo echo “export JAVA_HOME=/usr/lib/jvm/java-in-use” >> ~/.bashrc
sudo echo “export M2_HOME=/opt/maven” >> ~/.bashrc
sudo echo “export MAVEN_HOME=/opt/maven” >> ~/.bashrc
sudo echo “export PATH=${M2_HOME}/bin:${PATH}” >> ~/.bashrc
source ~/.bashrcnd make sure all is setup:

echo $JAVA_HOME
echo $M2_HOME
echo $MAVEN_HOME
echo $PATH
mvn -version

If you need to upgrade the link, repeated the process to download and extract, and update the symbolic link to the new value with the same ln command:

sudo ln -sfn /opt/apache-maven-3.9.6 /opt/maven

But if you do not need it anymore, you can delete the link:

sudo rm /opt/maven
Apache Maven logo with two feathers replacing the V letter
Apache Maven is ready!

IT’s my problem, maybe yours…

--

--