CentOS一键安装Maven
#!/bin/bash
# 下载 Maven 3.6.3 二进制发行包
wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz
# 解压 Maven 安装包
tar -zxvf apache-maven-3.8.8-bin.tar.gz
# 创建 Maven 安装目录并复制文件
mkdir -p /usr/local/maven3
cd apache-maven-3.8.8
cp -r * /usr/local/maven3
# 配置环境变量
echo "# Maven configurations" >> /etc/profile
echo "export M2_HOME=/usr/local/maven3" >> /etc/profile
echo "export PATH=\$PATH:\$JAVA_HOME/bin:\$M2_HOME/bin" >> /etc/profile
# 使环境变量生效
source /etc/profile
# 修改 Maven 配置文件
echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Aliyun Maven</name>
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
</settings>' > /usr/local/maven3/conf/settings.xml
source /etc/profile
echo "Maven 安装及配置完成!"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
上次更新: 2024/07/12, 13:19:37