要運行maven,必需要有 JDK ,maven 是由 Java 語言編寫的html
ORACLE 官網下載JDK jdk-8u231-linux-x64.tar.gzjava
[root@VM_0_17_centos /]# cd /opt [root@VM_0_17_centos opt]# mkdir jdk
# 修改 opt 文件夾權限 chmod 777 /opt # 修改 opt 文件夾及其子目錄的權限 chmod -R 777 /opt
[root@VM_0_17_centos jdk]# tar -zxvf jdk-8u231-linux-x64.tar.gz [root@VM_0_17_centos jdk]# ll total 189608 drwxr-xr-x 7 10 143 4096 Oct 5 18:13 jdk1.8.0_231 -rw-r--r-- 1 root root 194151339 Nov 6 20:07 jdk-8u231-linux-x64.tar.gz
在/etc/profile文件末尾追加下面幾行linux
[root@VM_0_17_centos jdk]# vi /etc/profile # 進入 vi 模式後 輸入兩個大 G ,定位到 文件末行
輸入 i 進入編輯模式apache
export JAVA_HOME=/opt/jdk/jdk1.8.0_231 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
按 Esc 鍵 ,輸入 :wq 保存並退出 viwindows
[root@VM_0_17_centos jdk]# source /etc/profile
[root@VM_0_17_centos jdk]# java -version java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
下載 maven Apache Maven 3.6.2centos
[root@VM_0_17_centos opt]# mkdir maven [root@VM_0_17_centos opt]# cd maven [root@VM_0_17_centos maven]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
建立文件夾,並切換到該目錄下,wget 會把地址對應的文件下載到該目錄服務器
[root@VM_0_17_centos maven]# ls apache-maven-3.6.2-bin.tar.gz [root@VM_0_17_centos maven]# tar -zxvf apache-maven-3.6.2-bin.tar.gz
[root@VM_0_17_centos maven]# ln -s apache-maven-3.6.2 maven [root@VM_0_17_centos maven]# ll total 8936 drwxr-xr-x 6 root root 4096 Nov 6 21:40 apache-maven-3.6.2 -rw-r--r-- 1 root root 9142315 Sep 3 05:43 apache-maven-3.6.2-bin.tar.gz lrwxrwxrwx 1 root root 18 Nov 6 21:43 maven -> apache-maven-3.6.2
ln –s 源文件 目標文件 是linux中的一個命令,windows中的快捷方式都知道吧,這個至關於給源文件建立了一個快捷方式,快捷方式的名稱叫作目標文件。
ln -s apache-maven-3.6.2 maven是指給apache-maven-3.6.2建立了一個快捷方式maven,訪問maven就至關於訪問apache-maven-3.6.2。
此處爲何須要用快捷方式?
之後升級maven更方便一些,之後若是咱們須要將maven升級到最新的版本,好比3.7,那麼只需下載3.7到當前目錄,再運行一下ln -s apache-maven-3.7 maven命令修改一下快捷方式的指向就好了,很方便。oracle
在/etc/profile文件末尾追加下面幾行maven
export M2_HOME=/opt/maven/maven export PATH=$M2_HOME/bin:$PATH
[root@VM_0_17_centos maven]# source /etc/profile
[root@VM_0_17_centos maven]# mvn -v Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00) Maven home: /opt/maven/maven Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /opt/jdk/jdk1.8.0_231/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.21.3.el7.x86_64", arch: "amd64", family: "unix"
<?xml version="1.0" encoding="UTF-8"?> <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 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>/opt/maven/repository</localRepository> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/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>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> <mirror> <id>OSChina</id> <name>OSChina Central</name> <url>http://maven.oschina.net/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>nexus-osc-thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <name>Nexus osc thirdparty</name> <url>http://maven.oschina.net/content/repositories/thirdparty/</url> </mirror> </mirrors> <profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> </profiles> </settings>
參考連接 :https://mp.weixin.qq.com/s/7LGakBJvQUjiVEUgdSe_Aw工具