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.


8 Answers 8


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

  • I will try and use the package in the repo you linked me to to guide my steps. Commented Jun 19, 2011 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. Commented Jun 19, 2011 at 19:36
  • tried this but it did not work. after closing the terminal it could not recognized the mvn command
    – user962206
    Commented Jun 19, 2013 at 9:03
  • @user962206 - please ask a new question.
    – fossfreedom
    Commented Jun 19, 2013 at 9:43
  • I already did askubuntu.com/questions/310059/…
    – user962206
    Commented Jun 19, 2013 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


  • 4
    This doesn't appear to work anymore. Commented Jun 9, 2015 at 16:25

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.

  • That only gives 3.0.5 (2016-02-05) but I would like 3.3.x - No way of getting that? Commented Feb 5, 2016 at 15:31

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 http://thejarbar.org
#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 http://mirrors.powertech.no/www.apache.org/dist//maven/binaries/apache-maven-$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/maven-mount.sh
    echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" >> $tempWork/maven-mount.sh
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" >> $tempWork/maven-mount.sh
    echo "echo 'mounted maven'" >> $tempWork/maven-mount.sh
    echo "exit 0" >> $tempWork/maven-mount.sh

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

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

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

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


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

    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

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


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.

  • BTW: to remove M2_HOME from ubuntu: see /etc/environment Commented Jan 18, 2013 at 17:03

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

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 linked 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

  • 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. Commented Apr 22, 2017 at 12:03

You must log in to answer this question.

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