Custom Search

Tuesday, June 4, 2013

Installing Maven on CentOS (RedHat Linux) Machine / System

You can download the Apache Maven to your Linux machine in two or more ways:

1. (a). Using "wget" commad as below:
Lets assume you want the file to be downloaded to your /tmp directory.
$ cd /tmp
$ wget

This should download from this mirror location.
But frankly speaking, I didn't get success this way even tried with couple of mirrors, I get normally below error when trying to download through above way:
--2013-06-04 04:31:05--
Resolving failed: Temporary failure in name resolution.
wget: unable to resolve host address âmirror.nexcess.netâ

1. (b). Download from Apache website to your windows local system. Here is the download location to Maven.
From your downloaded local windows system, FTP or use Filezilla or WinSCP (or similar tools) to upload to server (lets say to /tmp  directory on Linux).

Now we need to install (basically extract the Tar, in this case) the Maven on Linux:
Use below command (We are installing it on directory : /usr/local)
$ cd /tmp
$ sudo tar xzf apache-maven-3.0.5-bin.tar.gz -C /usr/local/

Assuming you have downloaded the 3.0.5 version of Maven with the file named as "apache-maven-3.0.5-bin.tar.gz" and kept at "/tmp"  folder. Similarly you can download and install any version of maven you like.

Now go to the /usr/local/ directory  and create a symbolic link for the folder "apache-maven-3.0.5" to be created named as "maven"
$ cd /usr/local
$ sudo ln -s apache-maven-3.0.5 maven

2.  Need to configure the Environment Variables to setup Maven work for us:
Create a script to be run automatically and which contains the Maven path setups.

$ sudo vi /etc/profile.d/
and  put below in this file, save and exit it:

export M2=$M2_HOME/bin
export PATH=$M2:${PATH}

Optionally: You can add the MAVEN_OPTS environment variable to specify JVM properties for memory tuning needed for your maven builds.
e.g. export MAVEN_OPTS="-Xms256m -Xmx512m".

You can close this putty session (close the putty window, or any other console you are using to type linux commands)  and Open a new session. Thats required, in order to get these new Variables picked up.

3. Now check the maven is setup correctly for you, by checking its version as below:
$ mvn -version

You should get some thing like below as a Result:
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 08:51:
Maven home: /usr/local/maven
Java version: 1.6.0_43, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_43/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-279.el6.i686", arch: "i386", family: "unix"

Congrats! You have successfully configured Maven on your Linux machine.
Now to build maven projects, you can follow this Getting Started Link.

No comments:

Post a Comment