64

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

2

9 Answers 9

57

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
9
  • is ' sudo apt-get --only-upgrade install maven ' upgrade maven to latest version 3.1.1 coz i tried it and still its 3.0.4
    – suja
    Feb 13, 2014 at 12:21
  • update your package list first with sudo apt-get update
    – Mina Eid
    Feb 13, 2014 at 13:08
  • if it doesn't work, try with wget
    – Mina Eid
    Feb 13, 2014 at 13:10
  • 3
    @MadhavanKumar that's because the last version published in apt is 3.0.4. You can always check that with sudo apt-get update to refresh your local cache; then apt-cache search maven and finally apt-cache showpkg <name-of-the-package> to see the current version. May 18, 2015 at 10:32
  • 6
    Does anyone know if Apache is going to update Maven on the Ubuntu repos? The package they host on the default repos still has bugs and it's been over a year. Aug 2, 2015 at 22:18
20

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"
1
  • The simplest and cleanest solution, no symbolic links to create. Thank you! Apr 11, 2016 at 17:15
10

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
10
  • 1
    it was /usr/bin/mvn3 in my case...
    – TomTasche
    May 24, 2014 at 11:54
  • 5
    This solution looks like good, but doesn't work with recent versions of Ubuntu, like 14.04. Oct 6, 2014 at 7:56
  • 2
    There's a PPA for Utopic at: launchpad.net/~vkorenev/+archive/ubuntu/maven3
    – Stoffe
    Mar 25, 2015 at 18:00
  • 2
    Also, a variation on the linking is to use update-alternatives: sudo update-alternatives --install "/usr/bin/mvn" "mvn" "/usr/share/maven3/bin/mvn" 1 then switch with sudo update-alternatives --config mvn
    – Stoffe
    Mar 25, 2015 at 18:01
  • 1
    Thank you, I used ppa.launchpad.net/vkorenev/maven3/ubuntu
    – ZiglioUK
    Apr 7, 2015 at 23:33
6

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

3
  • This is probably the more contemporary solution to use. Many thanks.
    – matanox
    Apr 9, 2016 at 12:11
  • E: Unable to locate package maven3 Mar 10, 2017 at 14:31
  • Great answer, I've been trying to make this work all day, thanks! Apr 7, 2017 at 22:13
5

I found this guide worked best for Ubuntu 14.04 to upgrade maven to 3.2.1 http://linuxg.net/how-to-install-apache-maven-3-2-1-on-ubuntu-14-04-linux-mint-17-and-their-derivative-systems/

First, remove the previous mavens of maven, do:

sudo apt-get remove maven*

Install Maven 3:

sudo apt-get install gdebi

wget http://ppa.launchpad.net/natecarlson/maven3/ubuntu/pool/main/m/maven3/maven3_3.2.1-0~ppa1_all.deb

sudo gdebi maven3_3.2.1-0~ppa1_all.deb

Symlink it, for an easier usage:

sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/maven
2
3

Tried the instructions here and the ones on apache.org. What ultimately fixed it was creating a symbolic link for maven:

sudo ln -s /usr/local/apache-maven/apache-maven-3.2.1/bin/mvn /usr/bin/mvn
2

If you are not comfortable with a PPA (personal package archive) where you have no assurance of the provenance this is an alternative.

From a security perspective if you don't know where it came from don't install it.

In my article I retrieve the latest file from apache which is a known and trusted source. You can get the latest version

#identify the latest version of maven
    latest=$(curl http://www-us.apache.org/dist/maven/maven-3/ | tac | sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,3\}[0-9]\).*/\1/p' | head -1)
#download it
    wget http://www-us.apache.org/dist/maven/maven-3/$latest/binaries/apache-maven-$latest-bin.tar.gz

then install it from

#Unpack it
    sudo tar -zxf apache-maven-$latest-bin.tar.gz -C /usr/local/
#create a sym link to it
    sudo ln -s /usr/local/apache-maven-$latest/bin/mvn /usr/bin/mvn

as outlined in the link above and my post on stackoverflow

2
  • 1
    Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places. Apr 22, 2017 at 12:03
  • 3
    @DavidPostill fair enough. But these are the questions that I searched and didn't find a useful answer on that is why I linked them together. Maybe when I build the reps I will do the duplicate but in the mean time I will raise a flag. Thanks for the advise.
    – TomRed
    Apr 22, 2017 at 12:10
1

Download the latest maven from http://maven.apache.org/download.cgi

wget http://apache-mirror.rbc.ru/pub/apache/maven/maven-3/3.2.2/binaries/apache-maven-3.2.2-bin.tar.gz
tar -zxf apache-maven-3.2.2-bin.tar.gz /tmp/
ln -s /tmp/apache-maven-3.2.2/bin/mvn /usr/local/bin/mvn

Check with

$ mvn -v
0

I just upgraded on mac and it was pretty easy. Get the maven from https://maven.apache.org/install.html Just add the maven~/bin to the PATH and update the JAVA_HOME. Then try out mvn -v to show the versions

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .