1. 解压缩

1
tar -zxvf apache-maven-3.6.1-bin.tar.gz

创建目录

1
mkdir -p /usr/local/maven

移动安装包

1
mv apache-maven-3.6.1/ /usr/local/maven/

2. 配置环境变量

1
vim /etc/profile

添加如下语句

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
if [ "$PS1" ]; then
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi

export MAVEN_HOME=/usr/local/maven/apache-maven-3.6.1
export PATH=$MAVEN_HOME/bin:$PATH:$HOME/bin

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi

使用户环境变量生效

1
source /etc/profile