採用以下步驟,在CentOS上安裝Maven。java
訪問MAVEN網站,下載Maven安裝包react
將下載後的tar.gz上傳到服務器上,並使用tar命令解壓linux
[root@dev18 srv]# tar -zvxf apache-maven-3.3.9-bin.tar.gz
執行ln -s命令建立一個連接。apache
[root@dev18 srv]# ln -s apache-maven-3.3.9 apache-maven
執行ll命令查看一下:bash
lrwxrwxrwx 1 root root 18 Dec 22 13:33 apache-maven -> apache-maven-3.3.9 drwxr-xr-x 6 root root 4096 Dec 22 13:33 apache-maven-3.3.9
使用 vi /etc/profile命令,服務器
[root@dev18 ~]# vi /etc/profile
添加以下內容:less
export M2_HOME=/srv/apache-maven export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
使用 source /etc/profile 讓新添加的環境變量生效。maven
[root@dev18 ~]# source /etc/profile
最後咱們可使用 mvn -v 命令來看一下Maven是否安裝成功。網站
[root@dev18 ~]# mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /srv/apache-maven Java version: 1.7.0_71, vendor: Oracle Corporation Java home: /usr/java/jdk1.7.0_71/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "2.6.32-573.el6.x86_64", arch: "amd64", family: "unix"
或者其它 Maven 命令如 mvn -h查看安裝後Maven的信息:ui
[root@dev18 ~]# mvn -h usage: mvn [options] [<goal(s)>] [<phase(s)>] Options: -am,--also-make If project list is specified, also build projects required by the list -amd,--also-make-dependents If project list is specified, also build projects that depend on projects on the list -B,--batch-mode Run in non-interactive (batch) mode -b,--builder <arg> The id of the build strategy to use. -C,--strict-checksums Fail the build if checksums don't match -c,--lax-checksums Warn if checksums don't match -cpu,--check-plugin-updates Ineffective, only kept for backward compatibility -D,--define <arg> Define a system property -e,--errors Produce execution error messages -emp,--encrypt-master-password <arg> Encrypt master security password -ep,--encrypt-password <arg> Encrypt server password -f,--file <arg> Force the use of an alternate POM file (or directory with pom.xml). -fae,--fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue -ff,--fail-fast Stop at first failure in reactorized builds -fn,--fail-never NEVER fail the build, regardless of project result -gs,--global-settings <arg> Alternate path for the global settings file -gt,--global-toolchains <arg> Alternate path for the global toolchains file -h,--help Display help information -l,--log-file <arg> Log file where all build output will go. -llr,--legacy-local-repository Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true -N,--non-recursive Do not recurse into sub-projects -npr,--no-plugin-registry Ineffective, only kept for backward compatibility -npu,--no-plugin-updates Ineffective, only kept for backward compatibility -nsu,--no-snapshot-updates Suppress SNAPSHOT updates -o,--offline Work offline -P,--activate-profiles <arg> Comma-delimited list of profiles to activate -pl,--projects <arg> Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path. -q,--quiet Quiet output - only show errors -rf,--resume-from <arg> Resume reactor from specified project -s,--settings <arg> Alternate path for the user settings file -T,--threads <arg> Thread count, for instance 2.0C where C is core multiplied -t,--toolchains <arg> Alternate path for the user toolchains file -U,--update-snapshots Forces a check for missing releases and updated snapshots on remote repositories -up,--update-plugins Ineffective, only kept for backward compatibility -V,--show-version Display version information WITHOUT stopping build -v,--version Display version information -X,--debug Produce execution debug output
至此,Maven安裝成功~~。