How to Install Apache Maven on CentOS 7
Apache Maven is a software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects, but can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. It not only describes how software builds but also its dependencies.
In this tutorial, we will show you step-by-step how to install and configure Apache Maven on a CentOS 7 system.
- CentOS 7 Server
- Root privileges
What we will do
- Install Java OpenJDK on CentOS 7
- Download Apache Maven Binary Files
- Configure Apache Maven Environment
Step 1 - Install Java OpenJDK on CentOS 7
The first thing we will do here is to install Java on the CentOS 7 server. Apache Maven requires JDK 1.7 or above - we will be using Java 8 that can be installed from the CentOS repository.
Install Java 8 on CentOS 7 using the yum command.
sudo yum install -y java-1.8.0-openjdk-devel
After the installation is complete, check the installed java version.
And you will get the result as below.
Java OpenJDK 8 has been installed on CentOS 7.
Step 2 - Download Apache Maven
In this step, we will download the apache maven binary code using the wget command. And we will be using the '/usr/local/src' directory as a maven home directory.
Go to the '/usr/local/src' directory and download the Apache Maven Binary code.
Extract the maven.tar.gz file, and then delete the compressed file.
tar -xf apache-maven-3.5.2-bin.tar.gz
rm -f apache-maven-3.5.2-bin.tar.gz
And you will get a new directory apache-maven-version - rename the directory.
mv apache-maven-3.5.2/ apache-maven/
Apache Maven is now downloaded in the '/usr/local/src/apache-maven' directory.
Step 3 - Configure Apache Maven Environment
In this step, we will configure the environment for Apache Maven. We will define some environment variables that are needed by Apache Maven.
Go to the '/etc/profile.d' directory and create a new configuration file 'maven.sh'.
Paste the following configuration there.
# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
Save and exit.
Now make the 'maven.sh' script executable and then apply the configuration by running the 'source' command.
chmod +x maven.sh
The Apache Maven environment configuration has been completed.
Step 4 - Testing
To verify our Apache Maven installation, you can run the maven command below.
And you should get a result similar to the following:
Apache Maven 3.2 installation has been completed. It's running under Linux CentOS 7 64bit, with Java 1.8 installed, and the Maven Home directory is '/usr/local/src/apache-maven'.