Installing Apache Maven in Ubuntu


Installing the latest binary

Copy the link of the latest binary at here.

$ cd /opt
$ sudo wget http://.../.../.../apache-maven-x.y.z-bin.tar.gz
$ ls -1F
apache-maven-x.y.z-bin.tar.gz
$ sudo tar -xzf apache-maven-x.y.z-bin.tar.gz
$ ls -1F
apache-maven-x.y.z/
apache-maven-x.y.z-bin.tar.gz
$ sudo ln -s apache-maven-x.y.z apache-maven-latest
$ ls -1F
apache-maven-x.y.z
apache-maven-x.y.z-bin.tar.gz
apache-mavenlatest@
$

Edit /etc/environment and append :/opt/apache-maven-latest/bin to PATH. Note that : character is a path separator.

$ cat /etc/environment
PATH="/../..:/opt/apache-maven-latest/bin"
$ source /etc/environment
$ which mvn
/opt/apache-maven-latest/bin/mvn
$ mvn --version
Apache Maven x.y.z ...
Maven home: /opt/apache-maven-latest
...

Upgrading to a newer version

When you need to upgrade to a newer version. Just extract the newer binary and change the symbolic link’s target with the -f option.

$ cd /opt
$ sudo wget http://.../.../.../apache-maven-9.9.9-bin.tar.gz
$ ls -1F
apache-maven-9.9.9-bin.tar.gz
$ sudo tar -xzf apache-maven-9.9.9-bin.tar.gz
$ ls -1F
apache-maven-9.9.9/
apache-maven-9.9.9.-bin.tar.gz
$ sudo ln -sf apache-maven-9.9.9 apache-maven-latest
$

Leave a comment