如何安装Maven 3?


27

我正在使用Ubuntu,需要从Maven 2升级到Maven3。有人可以帮我安装Maven 3吗?


从stackoverflow迁移了吗?真?带有Maven标签的SO上有1万个问题,而有关SU的只有9个,但是Maven问题不是真的与软件开发有关吗?
埃里克·威尔逊

Answers:



9

它不在存储库中,根据我的经验,最好的解决方案是从apache.org下载该文件,将其解压缩/home/youruser/maven,然后按照此处的说明将其添加到您的路径中。

当然,请先卸载当前的Maven 2。


我如何卸载maven 2

2
如果您是从ubuntu信息库中获取的,则执行'sudo apt-get uninstall
maven2'– ilcavero

7
没有理由卸载。
bmargulies

5
我相信它的apt-get remove,而不是apt-get卸载
Journeyman Geek

1
最好的下载页面是maven.apache.org/download.html,因为它始终保留最新版本
Brett Porter 2012年

3

我开始为我正在从事的项目设置Ubuntu 12.10。需要Maven 3来设置系统,并且事实证明,那里的大多数文档都涉及如何将Maven安装到Ubuntu 12.04或更低版本。

如果您想深入了解apt-get方面的ubuntu内核,并在何处找到可用于在Ubuntu上安装的应用程序列表,则手动安装很有用。如果您遇到的问题与我当时使用Ubuntu 12.10时遇到的问题相同,它对于Ubuntu的最新版本(如Ubuntu 13.04等)也可能很有用。我发现的最佳文档是:

killertilapia.blogspot.com.au/2012/10/installing-maven-3-in-ubuntu-1204.html

手动安装:

我想到的整个过程如下:

  1. 须藤-H gedit /etc/apt/sources.list
  2. 在sources.list文件中添加以下行:

    deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu精确主

    deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu精确主

  3. sudo apt-get更新&& sudo apt-get安装maven3

  4. 须藤ln -s / usr / share / maven3 / bin / mvn / usr / bin / mvn

注意1:命令“ sudo add-apt-repository ppa:natecarlson / maven3”在我的Ubuntu上不起作用,必须运行“ sudo add-apt-repository -rm ppa:natecarlson / maven3”才能使我的apt-get正常工作再次。

警告2:感谢David,您需要在运行步骤4之前删除现有的指向早期版本的maven的符号链接。

自动安装:

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

手动和自动安装的某些信息也可以在此处获得。


3
欢迎来到超级用户!虽然从理论上讲这可以回答问题,但最好在此处包括答案的基本部分,并提供链接以供参考。
slhck

thanx的答案。它与我一起工作于13.04 Ubuntu
mamdouh alramadan

0

请尝试以下我编写的旨在对Linux通用的脚本,检测VirtualBox的可能使用情况,并尝试从guest虚拟机挂载可能的文件(前提是已将它们设置为共享):

#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:."
export PATH

#Modify these variables as needed...
tempWork=/tmp/work
defaultStartScript=/etc/init.d/rc.local
defaultMaven=3.0.3
locBin=/usr/local/bin
mavenUsrLib=/usr/lib/maven

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
locStartScript=${locStartScript:-$defaultStartScript}

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


if [ ! -f $locStartScript ]
then
    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
fi

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 ]
then
    sudo /sbin/umount $HOME/.m2
    sudo /sbin/umount $mavenUsrLib
    sudo /sbin/mount.vboxsf .m2 $HOME/.m2
    sudo /sbin/mount.vboxsf maven $mavenUsrLib
fi

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

if ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locStartScript
then
    echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locStartScript
fi
    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 ]
then
    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
then
    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
then
    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

fi

#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
    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
fi

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

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

exit 0
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.