千家信息网

centos6.x中如何安装maven

发表于:2025-01-24 作者:千家信息网编辑
千家信息网最后更新 2025年01月24日,这篇文章主要介绍了centos6.x中如何安装maven,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。centos6.x下安装mave
千家信息网最后更新 2025年01月24日centos6.x中如何安装maven

这篇文章主要介绍了centos6.x中如何安装maven,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

centos6.x下安装maven

1.下载maven包

首先从官网上 http://maven.apache.org/ 下载最新版Maven。

本人下载包为apache-maven-3.2.1-bin.tar.gz

2.减压maven包

执行tar -zxvf apache-maven-3.2.1-bin.tar.gz

下图为减压成功页面

3.放在期望目录下(可选)

把减压好的文件放在/opt目录下

执行sudo mv apache-maven-3.2.1 /opt

4.更改链接

执行 ln -s apache-maven-3.2.1 apache-maven

5.配置环境变量

6.改动生效

执行source /etc/profile是profile文件生效

7.查看是否配置成功

执行mvn –v

出现上图表示安装成功。

CentOS自动安装Maven

1. 自动下载Maven
2. 设置环境变量
3. 配置mirror
安装:下载 maven.rar 按照 readme 执行即可
mirror配置:

      alimaven      aliyun maven      http://maven.aliyun.com/nexus/content/groups/public/      central          central      Maven Repository Switchboard      http://repo1.maven.org/maven2/      central          repo2      central      Human Readable Name for this Mirror.      http://repo2.maven.org/maven2/          ibiblio      central      Human Readable Name for this Mirror.      http://mirrors.ibiblio.org/pub/mirrors/maven2/          jboss-public-repository-group      central      JBoss Public Repository Group      http://repository.jboss.org/nexus/content/groups/public          maven.net.cn      oneof the central mirrors in china      http://maven.net.cn/content/groups/public/      central  

贴上shell 文件:

#!/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="  #     #       alimaven  #       aliyun maven  #       http://maven.aliyun.com/nexus/content/groups/public/  #       central  #     #     #       central  #       Maven Repository Switchboard  #       http://repo1.maven.org/maven2/  #       central  #     #     #       repo2  #       central  #       Human Readable Name for this Mirror.  #       http://repo2.maven.org/maven2/  #     #     #       ibiblio  #       central  #       Human Readable Name for this Mirror.  #       http://mirrors.ibiblio.org/pub/mirrors/maven2/  #     #     #       jboss-public-repository-group  #       central  #       JBoss Public Repository Group  #       http://repository.jboss.org/nexus/content/groups/public  #     #     #       maven.net.cn  #       oneof the central mirrors in china  #       http://maven.net.cn/content/groups/public/  #       central  #       #                                                                       '  "    #循环写入文件  for line in $mirror;  do    sed -i "/<\/mirrors>/i\ $line" $path/conf/settings.xml  done  IFS=$IFSBAK     #还原      echo "mvn -v"  mvn -v  echo ""

感谢你能够认真阅读完这篇文章,希望小编分享的"centos6.x中如何安装maven"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

0