Apache Maven is an open source build automation tool that is mainly used for creating JAVA based projects. Though used mainly for java projects, Apache maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.
To build a project, an XML file is described for the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins. It comes with pre-defined targets for performing certain well-defined tasks such as compilation of code and its packaging.
In this tutorial, we will learn to install Apache Maven on CentOS/RHEL systems. Using the same procedure mentioned below, we can also install Apache Maven on other Linux distributions like Ubuntu, Debian, Fedora etc.
(Recommended Read: Install JENKINS on CentOS/RHEL 7)
(Also Read: Complete guide for installing Apache TOMCAT)
Pre-requisites
We need to JAVA 1.7 or above to be installed on the system to run Apache Maven. You can check the installed Java version with the following command,
$ java –version
If java is not installed on your machine, please go through our detailed tutorial on how to install Java on your Linux machine. Once java has been installed, we can proceed ahead to install Apache Maven.
Installation
Firstly download the latest version of Apache Maven on your system by executing the following command from your terminal,
$ wget http://www-us.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz
Now extract the downloaded package ,
$ tar –xvzf apache-maven-3.5.2-bin.tar.gz
& move the contents of extracted package to ‘/opt’ (you can also use other folder for installation),
$ mv apache-maven-3.5.2/* /opt/maven
Next thing we need to do is to create a symbolic link to the maven executable,
$ ln -s /opt/maven/bin/mvn /usr/bin/mvn
Our maven installation is now complete but before we can start using it, we need set some environment variables. Execute the following command to set the environment variables permanently,
$ vi /etc/profile.d/maven.sh
& add the following lines to the file,
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
Save the file & exit. Now to load the environment variables for the current shell session, run the following command,
$ source /etc/profile.d/maven.sh
That’s it, maven is installed on our system & ready to build the projects.
We now end this tutorial on how to install Apache Maven on Linux machines. Please send in your queries or suggestions, if any , using the comment box below.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Donate us some of you hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.