How to update maven 3.0.4 - 3.1.1

First of all am new to Ubuntu as well as Maven. Does anyone know how to update maven. My current version of maven is 3.0.4. I would like to update it to 3.1.1 which is the latest version. I tried

sudo apt-get update maven

but this didn't help much. Any suggestion. Am using maven for first time. Also how to install

apache-maven-3.1.1-bin.tar.gz

I know there is an command like

sudo apt-get install maven

but it will download maven and then install it.. Since I may need to install maven on a few systems downloading it each time won't be a better option for us. So I am looking forward answer for two questions

  1. How to update installed maven

  2. How to install downloaded package of maven apache-maven-3.1.1-bin.tar.gz


To upgrade single package in terminal:

sudo apt-get --only-upgrade install maven

To Install downloaded package of maven apache-maven-3.1.1-bin.tar.gz

cd ~/Downloads
wget http://apache.mirrors.timporter.net/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz

sudo mkdir -p /usr/local/apache-maven
sudo mv apache-maven-3.1.1-bin.tar.gz /usr/local/apache-maven
cd /usr/local/apache-maven
sudo tar -xzvf apache-maven-3.1.1-bin.tar.gz

Edit ~/.profile with gedit ~/.profile and add these four lines:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$M2:$PATH

don't forget to execute following command to have the update without restarting the machine

 source ~/.profile

On the basis the original question asked about the latest version of Maven this PPA provides a backport from wily to trusty for Maven 3.3.9

https://launchpad.net/~andrei-pozolotin/+archive/ubuntu/maven3

Instructions to use this PPA are copied from the link above.

sudo apt-get purge maven maven2 maven3
sudo add-apt-repository ppa:andrei-pozolotin/maven3
sudo apt-get update
sudo apt-get install maven3

This worked fine for me on Ubuntu 14.04.3 LTS. The installed command was mvn without any need to add a symlink.

$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/share/maven3
Java version: 1.8.0_66, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.19.0-33-generic", arch: "amd64", family: "unix"

There is a PPA for maven with 3.1 at https://launchpad.net/~natecarlson/+archive/maven3

sudo add-apt-repository ppa:natecarlson/maven3

The only problem is that the command-line tool from the PPA is maven3, which is going to break any scripts calling mvn.

sudo ln -s /usr/bin/maven3 /usr/bin/mvn

To install mvn3 on Ubuntu 14.04, run:

sudo apt-get purge maven maven2 maven3
sudo add-apt-repository ppa:andrei-pozolotin/maven3
sudo apt-get update
sudo apt-get install maven3

To make a symbolic link, run:

sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn

Reference: https://launchpad.net/~andrei-pozolotin/+archive/ubuntu/maven3