I am using Ubuntu and need to upgrade to Maven 3 from Maven 2. Can someone please help me install Maven 3?

migrated from stackoverflow.com Jun 16 '11 at 14:06

This question came from our site for professional and enthusiast programmers.

  • Migrated from stackoverflow? Really? 10k questions on SO with Maven tag, and only 9 on SU, but Maven questions aren't really about software development? – Eric Wilson Dec 12 '12 at 18:34

There are two useful publications on this specific topic here:

PPA with Maven 3, built by Nate Carlson:


  • 3
    NB: you don't need to uninstall maven2 to have maven3 on your system. The maven3 PPA installs a binary called "mvn3" – Jay Taylor Jun 12 '12 at 23:39

It is not in the repositories, and from my experience the best solution is to download it from apache.org, untar it into /home/youruser/maven and then add it to your path like explained here.

Uninstall your current maven 2 before doing this of course.

  • how do I uninstall maven 2 – Ashish Agarwal Jun 16 '11 at 10:10
  • 2
    if you got it from the ubuntu repository, then do 'sudo apt-get uninstall maven2' – ilcavero Jun 16 '11 at 11:29
  • 6
    No reason to uninstall. – bmargulies Jun 16 '11 at 14:06
  • 4
    its apt-get remove , not apt-get uninstall, i believe – Journeyman Geek Oct 17 '11 at 13:39
  • 1
    The best download page to refer to is maven.apache.org/download.html, as it always retains the latest version – Brett Porter Jan 24 '12 at 19:19

I started setting up my Ubuntu 12.10 for the project I am working on. Maven 3 was required to set up the system and as it turns out most of the documents out there are referring to how to install Maven to Ubuntu version 12.04 or before.

The manual installation is useful if you like to dig in deeper to your ubuntu kernel in regards with apt-get and where it finds the list of applications that are available for installation on Ubuntu . It can also be potentially useful for more recent releases of Ubuntu like Ubuntu 13.04, etc. if you face the same problem as I did back then with Ubuntu 12.10. Best document I found was:


Manual installation:

The whole process I came up with is as follows:

  1. sudo -H gedit /etc/apt/sources.list
  2. Add the following line the sources.list file:

    deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main

    deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main

  3. sudo apt-get update && sudo apt-get install maven3

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

Caution 1: command "sudo add-apt-repository ppa:natecarlson/maven3" did not work on my Ubuntu and had to run "sudo add-apt-repository -rm ppa:natecarlson/maven3" to get my apt-get to work again.

Caution 2: thanks to David, you need to remove your existing symbolic link to previous versions of maven before running step 4.

Automatic Installation:

sudo apt-get remove maven2
sudo apt-get update
sudo apt-get install maven

Some information is also available here for both the manual and the automatic installation.

  • 2
    Welcome to Super User! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – slhck Jun 5 '13 at 12:44
  • thanx for the answer. It worked with me on 13.04 ubuntu – mamdouh alramadan Sep 8 '13 at 6:24

Try the following script I wrote aimed to be universal to Linux and detects possible use of VirtualBox and attempts to mount possible files from the guest (provided they are set up for sharing):

#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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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