下载Maven


前往http://maven.apache.org/download.cgi下载最新版的Maven[apache-maven-3.6.1-bin.tar.gz]。

将Maven压缩包上传到服务器

这里我将该安装包放在:/home/dimple/package/maven下。可以使用XFTP、WinSCP等工具上传。

执行解压命令

root@iZwz99z2ljzabken0hvkjrZ:/home/dimple/package/maven/apache-maven-3.6.1# tar -zxvf apache-maven-3.6.1-bin.tar.gz 

修改配置文件

修改/etc/profile文件,使用命令:

vim /etc/profile

添加以下片段:

M2_HOME=/home/dimple/package/maven/apache-maven-3.6.1 //对应你的安装目录
CLASSPATH=$CLASSPATH:$M2_HOME/lib PATH=$PATH:$M2_HOME/bin export PATH CLASSPATH M2_HOME

添加完成后的profile内容为:


# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
export JAVA_HOME=/home/dimple/package/java/jdk1.8.0_201
                  export JRE_HOME=${JAVA_HOME}/jre  
                  export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
                  export PATH=${JAVA_HOME}/bin:$PATH
# solr environment
export SOLR_INSTALL_HOME=/home/dimple/package/solr/solr-7.6.0
export PATH=$SOLR_INSTALL_HOME/bin:$PATH
# maven environment
M2_HOME=/home/dimple/package/maven/apache-maven-3.6.1
CLASSPATH=$CLASSPATH:$M2_HOME/lib
PATH=$PATH:$M2_HOME/bin
export   PATH    CLASSPATH   M2_HOME


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

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


然后刷新下source,使用以下命令:

source /etc/profile

测试是否成功

使用以下命令:

root@iZwz99z2ljzabken0hvkjrZ:/home/dimple/package/maven/apache-maven-3.6.1# mvn -version

输出:

root@iZwz99z2ljzabken0hvkjrZ:/home/dimple/package/maven/apache-maven-3.6.1# mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /home/dimple/package/maven/apache-maven-3.6.1
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /home/dimple/package/java/jdk1.8.0_201/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-93-generic", arch: "amd64", family: "unix"