centos6.x下安裝maven
1.下載maven包
首先從官網上 http://maven.apache.org/ 下載最新版Maven。
本人下載包為apache-maven-3.2.1-bin.tar.gz
執行tar -zxvf apache-maven-3.2.1-bin.tar.gz
把減壓好的文件放在/opt目錄下
執行sudo mv apache-maven-3.2.1 /opt
執行 ln -s apache-maven-3.2.1 apache-maven
執行source /etc/profile是profile文件生效
執行mvn –v
出現上圖表示安裝成功。
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>central</id> <name>Maven Repository Switchboard</name> <url>http://repo1.maven.org/maven2/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> <mirror> <id>ibiblio</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> </mirror> <mirror> <id>jboss-public-repository-group</id> <mirrorOf>central</mirrorOf> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> </mirror> <mirror> <id>maven.net.cn</id> <name>oneof the central mirrors in china</name> <url>http://maven.net.cn/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
#!/bin/sh #關閉進程 killpids(){ pids=($(ps -ef | grep $1 | awk '{print $2}')) for pid in ${pids[@]}; do echo "關閉進程: pid ${pid}" kill -9 ${pid} done } killpids maven #刪除舊版maven echo "刪除舊版maven" rm -rf /usr/local/apache-maven-* #install maven srcPath=$(find /usr/maven -maxdepth 1 -type f|grep '.*maven.*.tar.gz$') if [[ $srcPath =~ "maven" ]] then echo "安裝包:$srcPath" rpm -ivh $srcPath else #下載maven yum -y install wget echo -e "Download Maven" wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -P /usr/maven/ srcPath=$(find /usr/maven -maxdepth 1 -type f|grep '.*maven.*.tar.gz$') fi #解壓 echo "解壓..." tar -xf $srcPath -C /usr/local path=$(find /usr/local -maxdepth 1 -type d|grep 'apache-maven-.*') dir_name=${path##*/} echo $path echo $dir_name #賦予權限 chmod -R 755 $path #設置環境變量 sed -i '/M2_HOME/d' /etc/profile echo "設置環境變量" echo "export M2_HOME=$path" >> /etc/profile echo 'export PATH=$PATH:$M2_HOME/bin' >> /etc/profile source /etc/profile echo "建立軟鏈接 $path -> apache-maven" ln -s $path apache-maven echo "配置 mirrors" IFSBAK=$IFS #備份原來的值 IFS=# mirror=" # <mirror> # <id>alimaven</id> # <name>aliyun maven</name> # <url>http://maven.aliyun.com/nexus/content/groups/public/</url> # <mirrorOf>central</mirrorOf> # </mirror> # <mirror> # <id>central</id> # <name>Maven Repository Switchboard</name> # <url>http://repo1.maven.org/maven2/</url> # <mirrorOf>central</mirrorOf> # </mirror> # <mirror> # <id>repo2</id> # <mirrorOf>central</mirrorOf> # <name>Human Readable Name for this Mirror.</name> # <url>http://repo2.maven.org/maven2/</url> # </mirror> # <mirror> # <id>ibiblio</id> # <mirrorOf>central</mirrorOf> # <name>Human Readable Name for this Mirror.</name> # <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> # </mirror> # <mirror> # <id>jboss-public-repository-group</id> # <mirrorOf>central</mirrorOf> # <name>JBoss Public Repository Group</name> # <url>http://repository.jboss.org/nexus/content/groups/public</url> # </mirror> # <mirror> # <id>maven.net.cn</id> # <name>oneof the central mirrors in china</name> # <url>http://maven.net.cn/content/groups/public/</url> # <mirrorOf>central</mirrorOf> # </mirror> # ' " #循環寫入文件 for line in $mirror; do sed -i "/<//mirrors>/i/ $line" $path/conf/settings.xml done IFS=$IFSBAK #還原 echo "mvn -v" mvn -v echo ""
新聞熱點
疑難解答
圖片精選