Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Maven 2 is in the repositories, but not Maven 3. How do I properly install Maven 3? Guides that I found don't really work properly.

I am using Natty, but I am sure this won't change anything.

share|improve this question
up vote 25 down vote accepted

Maven3 is the default in Ubuntu 12.04 (precise)

Maven2 is the latest in the repositories for 11.10.

PPAs for maven3 seem rather scarce - here is one for maverick - although not the very latest version available.

The best advice is to stay with the stable version available for your distro version.

However if you like to keep up-to-date yourself it is very straightforward to download the code and install yourself.

Download the .tar.gz file from here and follow the installation guidance on the same web-page

share|improve this answer
I will try and use the package in the repo you linked me to to guide my steps. – nickguletskii Jun 19 '11 at 19:25
Right, this works. Thanks - I extracted files from the archive manually and replaced everything in /usr/share/maven3/ with files from the tar. – nickguletskii Jun 19 '11 at 19:36
tried this but it did not work. after closing the terminal it could not recognized the mvn command – user962206 Jun 19 '13 at 9:03
@user962206 - please ask a new question. – fossfreedom Jun 19 '13 at 9:43
I already did… – user962206 Jun 19 '13 at 11:53

Here is a maven3 PPA that worked fine for me on 64 bit Ubuntu 11.10

sudo add-apt-repository ppa:natecarlson/maven3
sudo apt-get update && sudo apt-get install maven3

If you have maven2 already installed from canonical repos this will not replace it but give you a mvn3 binary.

If you prefer to have the binary called mvn instead of mvn3 you can simply do the following:

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


share|improve this answer
This doesn't appear to work anymore. – KingOfHypocrites Jun 9 '15 at 16:25

I have made a new script that should not only install Maven + add it to bin, but picks up if you are using Ubuntu as a VirtualBox guest and then attempts to mount existing '.m2' and maven folder which may/may not contain existing settings.

Maven remains the same if it runs on Windows or Unix, so you can use same Maven between both is this is your VirtualBox setup...

PS. Note the build of scripts that can mount/unmount shared folders from the /usr/local/bin :)

#Author: Yucca Nel
#Will restart system
export PATH

#Modify these variables as needed...

mkdir -p $mavenUsrLib
mkdir -p $HOME/.m2

read -p "Please [Enter] full path name of your local startup script ($defaultStartScript is the default). Please
make sure on this before providing a value by consulting documentation for your system:" locStartScript

read -p "Please [Enter] Maven Version ($defaultMaven is default):" mavenVersion

if [ ! -f $locStartScript ]
    echo "The file you provided could not be found. Remember to include the full path and try again. Exiting in 7 secs..."
    sleep 7
    exit 1

mkdir -p /$tempWork
cd /$tempWork

sudo wget$mavenVersion-bin.tar.gz
tar -zxvf ./*

#Move it to a more logical location
sudo mv -f ./apache-maven-$mavenVersion $mavenUsrLib/

#If you have Maven on Windows and use VirtualBox, you can set up the maven to be a virtualbox shared folder.
#The name must match the name used below (ignore if irrelevant to you).

if [ -f /sbin/mount.vboxsf ]
    sudo /sbin/umount $HOME/.m2
    sudo /sbin/umount $mavenUsrLib
    sudo /sbin/mount.vboxsf .m2 $HOME/.m2
    sudo /sbin/mount.vboxsf maven $mavenUsrLib

if mountpoint -q $HOME/.m2 &&  mountpoint -q $mavenUsrLib
#Add it to the start script to automate process...
    sudo sed -ie '$d' $locStartScript
if ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locStartScript
    echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locStartScript

if ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locStartScript
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locStartScript
    echo "exit 0" | sudo tee -a $locStartScript
    sudo chmod +x $locStartScript

#Create a mount and unmount script file...
    rm -rf $tempWork/*
    echo '#!/bin/bash' > $tempWork/
    echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" >> $tempWork/
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" >> $tempWork/
    echo "echo 'mounted maven'" >> $tempWork/
    echo "exit 0" >> $tempWork/

    echo '#!/bin/bash' > $tempWork/
    echo "sudo umount $HOME/.m2" >> $tempWork/
    echo "sudo umount $mavenUsrLib" >> $tempWork/
    echo "echo 'unmounted maven'" >> $tempWork/
    echo 'exit 0' >> $tempWork/

#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/ ]
    echo '#!/bin/bash' > $tempWork/
    echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $tempWork/
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $tempWork/
    echo "exit 0" | sudo tee -a $tempWork/

#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locBin/
    sudo sed -ie '$d' $locBin/
    echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locBin/
    echo "exit 0" | sudo tee -a $locBin/

elif ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locBin/
    sudo sed -ie '$d' $locBin/
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locBin/
    echo "exit 0" | sudo tee -a $locBin/


#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/ ]
    echo '#!/bin/bash' > $tempWork/
    echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/
    echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/
    echo "exit 0" | sudo tee -a $tempWork/

    sudo chmod +x $tempWork/*
    sudo mv -f $tempWork/*.sh $locBin/
    rm -rf $tempWork

sudo ln -f -s $mavenUsrLib/apache-maven-$mavenVersion/bin/* /usr/bin/
sudo rm -rf $tempWork
sudo reboot

exit 0
share|improve this answer

Here is maven3 PPA which can resolve this issue.

Follow the installation:

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

And now you have installed maven3:

nazar@lelyak-desktop ~ $ mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T14:57:37+03:00)
Maven home: /usr/share/maven3
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-24-generic", arch: "amd64", family: "unix"

Link to Launchpad

share|improve this answer
Failed to fetch… 404 Not Found – habitats Feb 4 at 19:27

I upgraded but got a classnotfound error. To fix this:

After spending some time trying various combinations , I found that this is because I have both M2_HOME and M3_HOME set in my environment variables.Once I removed M2_HOME from my environment variables, I could get this working back again.May be this could save some serious time for some one.

share|improve this answer
BTW: to remove M2_HOME from ubuntu: see /etc/environment – RobAu Jan 18 '13 at 17:03

The question is old, but gold. I had to find a solution today. Here we go. There is no need to use an unsecure repository, because maven3 is already included in the Ubuntu repos. A solution at Ubuntu 14.04 LTS will be like:

  • sudo apt-get install maven
  • sudo update-alternatives --config mvn

With the 2nd command you're asked to set the used version. You can distinguish the correct directories by selecting the path where maven2 is NOT part of it.

   *0    /usr/share/maven2/bin/mvn   200       Auto-Modus
    1    /usr/share/maven/bin/mvn    150       manueller Modus
    2    /usr/share/maven2/bin/mvn   200       manueller Modus

In my case I had to select 1

With the issued command mvn -v you may verify, if the setting succeeded and whether you selected the correct version. Below you have an example of the returned values.

  ~$ mvn -version
  Apache Maven 3.0.5
  Maven home: /usr/share/maven
  Java version: 1.7.0_75, vendor: Oracle Corporation
  Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
  Default locale: de_DE, platform encoding: UTF-8
  OS name: "linux", version: "3.13.0-45-generic", arch: "amd64", family: "unix"

Hope this helps you a bit.

share|improve this answer
That only gives 3.0.5 (2016-02-05) but I would like 3.3.x - No way of getting that? – Kajetan Abt Feb 5 at 15:31

Download maven from maven official site and extract.

Move the application directory to /usr/local

sudo cp -R apache-maven-X.X.X /usr/local

Make a soft link in /usr/bin for universal access of mvn

sudo ln -s /usr/local/apache-maven-X.X.X/bin/mvn /usr/bin/mvn

Verifify mvn installation

mvn --version
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.