centos6.x下安装maven CentOS自动安装Maven的方法
https://www.518cn.com 发布时间:2025-03-18 09:09 作者:网络
摘要:这篇文章主要介绍了centos6.x下安装maven CentOS自动安装Maven,需要的朋友可以参考下
2.减压maven包
3.放在期望目录下(可选)
4.更改链接
5.配置环境变量
6.改动生效
7.查看是否配置成功
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
CentOS自动安装Maven
1. 自动下载Maven
2. 设置环境变量
3. 配置mirror
安装:下载 maven.rar 按照 readme 执行即可
mirror配置:
2. 设置环境变量
3. 配置mirror
安装:下载 maven.rar 按照 readme 执行即可
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>
贴上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=" # <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 ""
相关文章
Centos7.8怎么更新openssh? Centos升级openssh的技巧
Centos7.8怎么更新openssh?Centos7.8系统想要安装openssh,该怎么安装呢?下面我们就来看看Centos升级...03-18Centos7.8怎么更新openssl? CentOS升级OpenSSL的技巧
Centos7.8怎么更新openssl?Centos7.8系统想要升级OpenSSL,该怎么升级呢?详细请看下文介绍...03-18- centos7没有图形化操作可能对很多人来说都不太习惯,下面我们来为centos7安装图形化界面,本文...03-18
- 今天小编在安装RHEL7的时候,一步留神没有安装图形化桌面,下面分享一下安装图形化桌面的过...03-18
- 下载CentOS-7.0-1406的时候,有很多可选则的版本,对于普通用户来说,不知道选择哪个好,下面...03-18
Centos 7怎么手动配置ip地址? Centos7配置IP地址的技
Centos 7怎么手动配置ip地址?Centos 7系统想要自己配置ip地址,该怎么操作呢?下面我们就来看看...03-18- 这篇文章主要介绍了Centos 7 压缩与解压缩命令小结,需要的朋友可以参考下...03-18
- 这篇文章主要介绍了Centos7 yum安装git服务器,需要的朋友可以参考下...03-18
CentOS 6.6系统怎么安装?CentOS Linux系统安装配置图
CentOS系统怎么安装?今天小编就为大家带来了CentOS Linux系统安装配置图解教程,需要的朋友可...03-18在vmware虚拟机中安装Linux系统CentOS7详细教程
这篇文章主要为大家分享在虚拟机中安装Linux系统CentOS7的方法,非常详细,看了这篇基本上都...03-18
最新评论