How to install Maven 3 on Ubuntu 18.04/17.04/16.10/16.04 LTS/15.10/15.04/14.10/14.04 LTS/13.10/13.04 by using apt-get? [closed]
Asked Answered
W

2

305

Try:

sudo apt-get install maven

If it works for you ignore the rest of this post.

Intro

I started setting up my Ubuntu 12.10 on April 2013 and the normal sudo apt-get install maven was not working for maven 3 back then.

The manual installation in this post 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 15.04, etc. if you face the same problem as I did back then with Ubuntu 12.10.

Automatic Installation via apt-get:

Checkout the manual installation if your current ubuntu can not install maven via common 'apt-get install maven'.

sudo apt-get update
sudo apt-get install maven

Make sure to remove maven 2 if your ubuntu is not fresh or if you were using maven 2 before:

sudo apt-get remove maven2

Manual Installation via apt-get by adding maven 3 repository (Ubuntu 14.04 check out update 1):

This can be useful if your ubuntu apt-get repositories list is not up to date.

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. Best document I found was:

killertilapia's blog

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 apt-add-repository ppa:natecarlson/maven3" did not work on my Ubuntu and had to run sudo apt-add-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.

OS X Installation

I decided to add OS X installation in case you use multiple environments for your dev: See the source stackoverflow thread for more details.

Install Homebrew that is the equavalent of apt-get, then install Maven using:

brew install maven

Update 1: Installation for Ubunutu 14.04

Haven't tried this myself but I am confident this should work without security warnings:

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

Note: source here, many thanks and +1s to @rendybjunior, @Dominic_Bartl, and @FunThomas424242

Wheal answered 26/3, 2013 at 5:33 Comment(12)
I needed to run "rm /usr/bin/mvn" before making the symbolic link because I already had Maven 2. After installing Maven 3, you can still access Maven 2 using /usr/share/maven2/bin/mvnKier
Asking how to install programming tools is generally regarded as on-topic: meta.stackexchange.com/q/130246/38765Chaps
What is the question?Stenophagous
@richard this is Q&A style. In other term the question and answer are both in the same thread. This is becoming a good way for people to share the solutions they come across. They just simply add a Q&A to stackoverflow and share it with people. :-)Wheal
for the lazy sudo add-apt-repository ppa:natecarlson/maven3Proficient
At lubuntu 14.04 aptitude raised a security warning.Bendy
@Wheal It's fine to answer your own question, but you need to post the answer as an answer, not in the question.Wojcik
On askubuntu: askubuntu.com/questions/49557/how-do-i-install-maven-3Hagood
Use this ppa for your trusty 14.04 launchpad.net/~andrei-pozolotin/+archive/ubuntu/maven3Ahner
There is a way to install Maven using portable binary, I wrote a Maven cookbook that I use for work: github.com/gdbtek/ubuntu-cookbooks/blob/master/cookbooks/maven/…Olindaolinde
Someone really dropped the ball on updating maven in Ubuntu 14.04, 14.10, and 15.04. Luckily 15.10 LTS is getting an update to version 3.3.Improve
@TomDworzanski indeed they did! Great to here this is not going to be the case anymore. It was a nightmare back in the day when I faced the installation issue.Wheal
K
226

Here's an easier way:

sudo apt-get install maven

More details are here.

Krahling answered 15/5, 2013 at 13:25 Comment(10)
I tried this too. This seems to work as well that is great. Just make sure you run sudo apt-get update first especially if you have a fresh install of ubunut 12.Wheal
You may also need to do sudo apt-get remove maven2; just installing Maven 3 with sudo apt-get install maven doesn't necessarily make it the default version of Maven.Nexus
@TheHippo, the apt-get repositories must have been fixed by now but when I did my installation on Ubunut 12.10 normal apt-get install was not working.Wheal
Use this command to select the correct version of maven after it's been installed: sudo update-alternatives --config mvnPlatysma
I get a lot of '403 forbidden' when I try to install maven. Any idea what the issue is?Veradi
@Veradi are you behind a proxy? If so, 403 may comes from your proxy server.Vitriolize
What does sudo apt-get install maven2 do? Older version 2?Fluorometer
This doesn't allow to install latest maven version. E.g. I need 3.3.3, but only 3.0.5 is available. Ubuntu 14.04.Cookout
As of 2016 April Ubuntu installs maven version 3.0.4. This may not be recent enough for you. For example frontend-maven-plugin v.1.0 needs at least 3.1.xPademelon
Error: unable to locate package mavenSexagesima
L
10

It's best to use miske's answer.

Properly installing natecarlson's repository

If you really want to use natecarlson's repository, the instructions just below can do any of the following:

  1. set it up from scratch
  2. repair it if apt-get update gives a 404 error after add-apt-repository
  3. repair it if apt-get update gives a NO_PUBKEY error after manually adding it to /etc/apt/sources.list

Open a terminal and run the following:

sudo -i

Enter your password if necessary, then paste the following into the terminal:

export GOOD_RELEASE='precise'
export BAD_RELEASE="`lsb_release -cs`"
cd /etc/apt
sed -i '/natecarlson\/maven3/d' sources.list
cd sources.list.d
rm -f natecarlson-maven3-*.list*
apt-add-repository -y ppa:natecarlson/maven3
mv natecarlson-maven3-${BAD_RELEASE}.list natecarlson-maven3-${GOOD_RELEASE}.list
sed -i "s/${BAD_RELEASE}/${GOOD_RELEASE}/" natecarlson-maven3-${GOOD_RELEASE}.list
apt-get update
exit
echo Done!

Removing natecarlson's repository

If you installed natecarlson's repository (either using add-apt-repository or manually added to /etc/apt/sources.list) and you don't want it anymore, open a terminal and run the following:

sudo -i

Enter your password if necessary, then paste the following into the terminal:

cd /etc/apt
sed -i '/natecarlson\/maven3/d' sources.list
cd sources.list.d
rm -f natecarlson-maven3-*.list*
apt-get update
exit
echo Done!
Lewse answered 1/6, 2013 at 2:32 Comment(3)
If you use saucy, then just edit the file "/etc/apt/sources.list.d/natecarlson-maven3-saucy.list" and replace saucy with precise. This tells it to use the precise repository, but this is not important in this case, because maven doesn't rely much on dependencies.Bargainbasement
btw the command is mvn3 not mvn using the repo.Bargainbasement
You probably should echo Done! before you exit. +1 nonetheless :)Improve

© 2022 - 2024 — McMap. All rights reserved.