<div class="it610-blog-content-contain" style="font-size: 14px"></div>
一、环境说明:
操作系统:Ubuntu 12.04.2 LTS
maven:apache-maven-3.2.3
安装maven前请先安装好jdk,jdk安装可参见:http://my.oschina.net/hongdengyan/blog/150342。
二、下载 maven
下载链接:http://maven.apache.org/download.cgi
选择最新版本的maven安装包,我安装时最新安装包是apache-maven-3.2.3-bin.tar.gz
下载保存文件的路径是:~/下载/。
三、解压安装
xcw@xcw-Lenovo-G470:~$ tar -xzvf apache-maven-3.2.3-bin.tar.gz
四、设置环境变量
以root身份打开并编辑profile文件:
xcw@xcw-Lenovo-G470:~$ sudo gedit /etc/profile
在文件最后添加:
#set maven environment
M2_HOME=/usr/local/apache-maven-3.1.0
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$M2_HOME/bin:$PATH
保存并关闭。
要使配置生效必须重启机器或者在命令行输入:
xcw@xcw-Lenovo-G470:~$ . /etc/profile
xcw@xcw-Lenovo-G470:~$ mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T04:58:10+08:00)
Maven home: /home/xcw/apache-maven
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: /home/xcw/jdk1.8.0_11/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-17-generic", arch: "i386", family: "unix"
在这里提供一种其它的方式:
//在你安装目录的统一路径下创建一个平行目录,类似与链接 xcw@xcw-Lenovo-G470:~$ ln-s apache-maven-3.2.3 apache-maven xcw@xcw-Lenovo-G470:~$ ls -1 xcw@xcw-Lenovo-G470:~$ export M2_HOME=/home/xcw/apache-maven xcw@xcw-Lenovo-G470:~$ export PATH=$PATH:$M2_HOME/bin 一般情况下其我们需要用脚本去,在profile中增加以下几行
#set maven environment M2_HOME=/home/xcw/apache-maven export MAVEN_OPTS="-Xms256m -Xmx512m" export PATH=$M2_HOME/bin:$PATH
五、配置用户范围setting.xml
yan@yan-Ubuntu:/$ sudo cp /usr/local/apache-maven-3.1.0/conf/settings.xml ~/.m2
yan@yan-Ubuntu:/$ sudo gedit ~/.m2/settings.xml
在文件找到
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> -->
加入
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>/home/yan/code/repository/maven</localRepository>