当前位置: 首页>>技术教程>>正文


如何安装Maven 3?

, ,

问题描述

Maven 2位于存储库中,但不是Maven 3.如何正确安装Maven 3?我找到的指南并没有真正起作用。

我正在使用Natty,但我相信这不会改变任何东西。

最佳解决办法

Maven3是Ubuntu 12.04的默认设置(精确)

Maven2是11.10的最新版本。

maven3的PPA似乎相当稀少 – 这里是maverick的PPA – 尽管不是最新版本。

最好的建议是使用适用于您的发行版的稳定版本。

但是,如果您想自己保留up-to-date,下载代码并自行安装非常简单。

here下载.tar.gz文件,并按照相同web-page上的安装指南

次佳解决办法

这是一个maven3 PPA,在64位Ubuntu 11.10上运行良好

sudo add-apt-repository ppa:natecarlson/maven3
sudo apt-get update && sudo apt-get install maven3

如果您已经从规范存储库安装了maven2,则不会替换它,但会为您提供mvn3二进制文件。

如果您希望使用名为mvn而不是mvn3的二进制文件,则只需执行以下操作:

sudo ln -s /usr/bin/mvn3 /usr/bin/mvn

Source

第三种解决办法

问题是陈旧的,但金。我今天必须找到解决方案。开始了。不需要使用不安全的存储库,因为maven3已经包含在Ubuntu存储库中。 Ubuntu 14.04 LTS的解决方案如下:

  • sudo apt-get install maven

  • sudo update-alternatives --config mvn

使用第2个命令,您需要设置使用的版本。您可以通过选择maven2不属于它的路径来区分正确的目录。

   *0    /usr/share/maven2/bin/mvn   200       Auto-Modus
    1    /usr/share/maven/bin/mvn    150       manueller Modus
    2    /usr/share/maven2/bin/mvn   200       manueller Modus

在我的情况下,我必须选择1

使用发出的命令mvn -v,您可以验证设置是否成功以及是否选择了正确的版本。下面是一个返回值的示例。

  ~$ mvn -version
  Apache Maven 3.0.5
  Maven home: /usr/share/maven
  Java version: 1.7.0_75, vendor: Oracle Corporation
  Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
  Default locale: de_DE, platform encoding: UTF-8
  OS name: "linux", version: "3.13.0-45-generic", arch: "amd64", family: "unix"

希望这对你有所帮助。

第四种办法

我已经创建了一个新脚本,不仅应该安装Maven +将其添加到bin中,而是在使用Ubuntu作为VirtualBox guest虚拟机然后尝试安装现有的’.m2’和maven文件夹(可能/可能不包含现有设置)时启动。

如果它在Windows或Unix上运行,Maven保持不变,所以你可以在两者之间使用相同的Maven这是你的VirtualBox设置……

PS。请注意可以从/usr /local /bin安装/卸载共享文件夹的脚本的构建:)

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

第五种办法

这是maven3 PPA可以解决这个问题。

按照安装:

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

现在你已经安装了maven3:

nazar@lelyak-desktop ~ $ mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T14:57:37+03:00)
Maven home: /usr/share/maven3
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-24-generic", arch: "amd64", family: "unix"

Link to Launchpad

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2381.html,未经允许,请勿转载。