手动安装:

手动安装:

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

答案1

答案2

它不在存储库中,根据我的经验,最好的解决方案是从 apache.org 下载,将其解压到/home/youruser/maven,然后将其添加到你的路径中,例如这里解释

当然,在执行此操作之前,请先卸载当前的 maven 2。

答案3

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

如果您想深入了解 Ubuntu 内核,了解 apt-get 以及它如何找到可在 Ubuntu 上安装的应用程序列表,那么手动安装非常有用。对于较新的 Ubuntu 版本,例如Ubuntu 13.04等等。如果你遇到和我当时使用 Ubuntu 12.10 时遇到的相同问题。我找到的最佳文档是:

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

手动安装:

我想到的整个过程如下:

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

    德布http://ppa.launchpad.net/natecarlson/maven3/ubuntu精准主

    deb-源文件http://ppa.launchpad.net/natecarlson/maven3/ubuntu精准主

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

  4. sudo 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

还有一些信息这里用于手动和自动安装。

答案4

尝试以下我编写的脚本,旨在通用 Linux检测可能使用 VirtualBox 并尝试从客户机挂载可能的文件(前提是这些文件已设置为共享):

#!/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

相关内容