How to install Apache Maven on CentOS server

Reference Server

Share

In this tutorial we will learn to install Apache Maven which is a software project management and comprehension tool on CentOS.

Prerequisite

It is assumed that you have wget installed.

Use the following command in the terminal to install wget.

yum install -y wget

And it is also assumed that you have zip and unzip installed.

Use the following command in the terminal to install zip and unzip.

yum install -y zip unzip

Use sudo if you don't have the permissions.

Step 1 Download Apache Maven

Open terminal and login to your server using ssh. Now cd to a directory where you want to download the files.

Lets say we have a Downloads directory and we want to download Apache Maven in that directory.

Type the following in the terminal to download Apache Maven.

wget http://redrockdigimark.com/apachemirror/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip

Output

[~]# cd Downloads
[Downloads]# wget http://redrockdigimark.com/apachemirror/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip
--2016-12-12 02:52:31--  http://redrockdigimark.com/apachemirror/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip
Resolving redrockdigimark.com (redrockdigimark.com)... 119.18.61.94
Connecting to redrockdigimark.com (redrockdigimark.com)|119.18.61.94|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8617253 (8.2M) [application/zip]
Saving to: ‘apache-maven-3.3.9-bin.zip’

100%[==================================================================================================>] 8,617,253   3.11MB/s   in 2.6s   

2016-12-12 02:52:34 (3.11 MB/s) - ‘apache-maven-3.3.9-bin.zip’ saved [8617253/8617253]

[Downloads]#

Now we can ls to check the downloaded zip file.


[Downloads]# ls -la
total 1232052
drwxr-xr-x  2 root root       4096 Apr 10 02:52 .
dr-xr-x---. 6 root root       4096 Apr 10 06:00 ..
-rw-r--r--  1 root root    8617253 Nov 18  2015 apache-maven-3.3.9-bin.zip
[Downloads]# 

Step 2 Unzip the file

Use the following command in the terminal to unzip the downloaded file.

unzip apache-maven-3.3.9-bin.zip

Output

[Downloads]# unzip apache-maven-3.3.9-bin.zip 
Archive:  apache-maven-3.3.9-bin.zip
   creating: apache-maven-3.3.9/
   creating: apache-maven-3.3.9/boot/
  inflating: apache-maven-3.3.9/boot/plexus-classworlds-2.5.2.jar  
   creating: apache-maven-3.3.9/lib/
  inflating: apache-maven-3.3.9/lib/maven-embedder-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/maven-settings-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/plexus-utils-3.0.22.jar  
  inflating: apache-maven-3.3.9/lib/maven-core-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/maven-model-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/commons-lang3-3.4.jar  
  inflating: apache-maven-3.3.9/lib/maven-settings-builder-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/maven-builder-support-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/plexus-interpolation-1.21.jar  
  inflating: apache-maven-3.3.9/lib/plexus-component-annotations-1.6.jar  
  inflating: apache-maven-3.3.9/lib/plexus-sec-dispatcher-1.3.jar  
  inflating: apache-maven-3.3.9/lib/plexus-cipher-1.7.jar  
  inflating: apache-maven-3.3.9/lib/maven-repository-metadata-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/maven-artifact-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/maven-plugin-api-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/org.eclipse.sisu.plexus-0.3.2.jar  
  inflating: apache-maven-3.3.9/lib/cdi-api-1.0.jar  
  inflating: apache-maven-3.3.9/lib/jsr250-api-1.0.jar  
  inflating: apache-maven-3.3.9/lib/javax.inject-1.jar  
  inflating: apache-maven-3.3.9/lib/org.eclipse.sisu.inject-0.3.2.jar  
  inflating: apache-maven-3.3.9/lib/maven-model-builder-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/guava-18.0.jar  
  inflating: apache-maven-3.3.9/lib/maven-aether-provider-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/aether-api-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/aether-spi-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/aether-util-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/aether-impl-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/guice-4.0-no_aop.jar  
  inflating: apache-maven-3.3.9/lib/aopalliance-1.0.jar  
  inflating: apache-maven-3.3.9/lib/maven-compat-3.3.9.jar  
  inflating: apache-maven-3.3.9/lib/wagon-provider-api-2.10.jar  
  inflating: apache-maven-3.3.9/lib/slf4j-api-1.7.5.jar  
  inflating: apache-maven-3.3.9/lib/commons-cli-1.2.jar  
  inflating: apache-maven-3.3.9/lib/wagon-http-2.10-shaded.jar  
  inflating: apache-maven-3.3.9/lib/wagon-http-shared-2.10.jar  
  inflating: apache-maven-3.3.9/lib/jsoup-1.7.2.jar  
  inflating: apache-maven-3.3.9/lib/commons-lang-2.6.jar  
  inflating: apache-maven-3.3.9/lib/commons-io-2.2.jar  
  inflating: apache-maven-3.3.9/lib/wagon-file-2.10.jar  
  inflating: apache-maven-3.3.9/lib/aether-connector-basic-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/aether-transport-wagon-1.0.2.v20150114.jar  
  inflating: apache-maven-3.3.9/lib/slf4j-simple-1.7.5.jar  
  inflating: apache-maven-3.3.9/README.txt  
  inflating: apache-maven-3.3.9/LICENSE  
  inflating: apache-maven-3.3.9/NOTICE  
  inflating: apache-maven-3.3.9/lib/aether-api.license  
  inflating: apache-maven-3.3.9/lib/aether-connector-basic.license  
  inflating: apache-maven-3.3.9/lib/aether-impl.license  
  inflating: apache-maven-3.3.9/lib/aether-spi.license  
  inflating: apache-maven-3.3.9/lib/aether-transport-wagon.license  
  inflating: apache-maven-3.3.9/lib/aether-util.license  
  inflating: apache-maven-3.3.9/lib/cdi-api.license  
  inflating: apache-maven-3.3.9/lib/commons-lang3.license  
  inflating: apache-maven-3.3.9/lib/jsoup.license  
  inflating: apache-maven-3.3.9/lib/jsr250-api.license  
  inflating: apache-maven-3.3.9/lib/maven-aether-provider.license  
  inflating: apache-maven-3.3.9/lib/maven-artifact.license  
  inflating: apache-maven-3.3.9/lib/maven-builder-support.license  
  inflating: apache-maven-3.3.9/lib/maven-compat.license  
  inflating: apache-maven-3.3.9/lib/maven-core.license  
  inflating: apache-maven-3.3.9/lib/maven-embedder.license  
  inflating: apache-maven-3.3.9/lib/maven-model-builder.license  
  inflating: apache-maven-3.3.9/lib/maven-model.license  
  inflating: apache-maven-3.3.9/lib/maven-plugin-api.license  
  inflating: apache-maven-3.3.9/lib/maven-repository-metadata.license  
  inflating: apache-maven-3.3.9/lib/maven-settings-builder.license  
  inflating: apache-maven-3.3.9/lib/maven-settings.license  
  inflating: apache-maven-3.3.9/lib/org.eclipse.sisu.inject.license  
  inflating: apache-maven-3.3.9/lib/org.eclipse.sisu.plexus.license  
  inflating: apache-maven-3.3.9/lib/plexus-cipher.license  
  inflating: apache-maven-3.3.9/lib/plexus-sec-dispatcher.license  
  inflating: apache-maven-3.3.9/lib/slf4j-api.license  
  inflating: apache-maven-3.3.9/lib/slf4j-simple.license  
  inflating: apache-maven-3.3.9/lib/wagon-file.license  
  inflating: apache-maven-3.3.9/lib/wagon-http-shared.license  
  inflating: apache-maven-3.3.9/lib/wagon-http.license  
  inflating: apache-maven-3.3.9/lib/wagon-provider-api.license  
   creating: apache-maven-3.3.9/bin/
  inflating: apache-maven-3.3.9/bin/m2.conf  
  inflating: apache-maven-3.3.9/bin/mvn.cmd  
  inflating: apache-maven-3.3.9/bin/mvnDebug.cmd  
  inflating: apache-maven-3.3.9/bin/mvn  
  inflating: apache-maven-3.3.9/bin/mvnDebug  
  inflating: apache-maven-3.3.9/bin/mvnyjp  
   creating: apache-maven-3.3.9/conf/
   creating: apache-maven-3.3.9/conf/logging/
  inflating: apache-maven-3.3.9/conf/logging/simplelogger.properties  
  inflating: apache-maven-3.3.9/conf/settings.xml  
  inflating: apache-maven-3.3.9/conf/toolchains.xml  
   creating: apache-maven-3.3.9/lib/ext/
  inflating: apache-maven-3.3.9/lib/ext/README.txt

We can now ls to check the unzipped directory.


[Downloads]# ls -la
total 1232056
drwxr-xr-x  3 root root       4096 Apr 10 02:53 .
dr-xr-x---. 6 root root       4096 Apr 10 06:00 ..
drwxr-xr-x  6 root root       4096 Nov 10  2015 apache-maven-3.3.9
-rw-r--r--  1 root root    8617253 Nov 18  2015 apache-maven-3.3.9-bin.zip

Step 3 Move to opt directory

Now we will move the unzipped Maven directory to opt directory.

Use the mv command in the terminal to move the directory.

[Downloads]# mv apache-maven-3.3.9 /opt/
[Downloads]# cd /opt
[opt]# ls -la
total 20
drwxr-xr-x.  5 root root 4096 Apr 10 02:53 .
drwxr-xr-x  18 root root 4096 Apr 10 06:05 ..
drwxr-xr-x   6 root root 4096 Nov 10  2015 apache-maven-3.3.9
[opt]# 

Step 4 Set the environment

Time for us to edit the .bash_profile file.

[opt]# cd
[~]# ls -la
total 96
dr-xr-x---.  8 root root  4096 Dec 31 20:15 .
drwxr-xr-x  18 root root  4096 Dec 29 06:15 ..
-rw-------.  1 root root 11146 Dec 31 20:39 .bash_history
-rw-r--r--.  1 root root    18 Dec 29  2013 .bash_logout
-rw-r--r--   1 root root   429 Dec 31 10:38 .bash_profile

Open the .bash_profile file using vi or vim.

[~]# vi .bash_profile

And now add the following lines. Press i key to switch into INSERT mode.

export APACHE_MAVEN=/opt/apache-maven-3.3.9

PATH=$HOME/bin:$APACHE_MAVEN/bin:$PATH

export PATH

Press Esc key to come out of the INSERT mode. Now type :wq to save the changes and exit.

Now, load the changes using source command.

[~]# source .bash_profile

Now we can check the Apache Maven version by typing the following command in the terminal.

[~]# mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /opt/apache-maven-3.3.9
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_79/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.9.7-x86_64-linode80", arch: "amd64", family: "unix"

Congratulation! You have successfully installed Apache Maven on your CentOS server. Have fun :-)

Share