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

4

2 回答 2

227

这是一个更简单的方法:

sudo apt-get install maven

更多细节在这里

于 2013-05-15T13:25:08.760 回答
10

最好使用miske 的答案

正确安装 natecarlson 的存储库

如果您真的想使用 natecarlson 的存储库,下面的说明可以执行以下任何操作:

  1. 从头开始设置
  2. apt-get update如果之后出现404错误,请修复它add-apt-repository
  3. 如果手动添加后apt-get update出现错误,请修复它NO_PUBKEY/etc/apt/sources.list

打开终端并运行以下命令:

sudo -i

如有必要,输入您的密码,然后将以下内容粘贴到终端中:

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!

删除 natecarlson 的存储库

如果您安装了 natecarlson 的存储库(使用add-apt-repository或手动添加到/etc/apt/sources.list)并且不再需要它,请打开终端并运行以下命令:

sudo -i

如有必要,输入您的密码,然后将以下内容粘贴到终端中:

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!
于 2013-06-01T02:32:28.983 回答