Apache Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT.
In this tutorial we will show you two different ways to install Apache Maven on CentOS 7 / Rhel 7: Using the yum
package manager or by a source from the official website.
Prerequisites
You’ll need to be logged in as a user with sudo
privileges in order to install the Apache Maven.
Method 1./ Installing Apache Maven using Yum
– The official CentOS repositories contains Maven packages that can be installed with the yum
package manager. Use the below command:
# sudo yum install maven
– To verify if Apache Maven is successfully installed just run the mvn -version
command:
# mvn -version Apache Maven 3.0.5 (Red Hat 3.0.5-17) Maven home: /usr/share/maven Java version: 1.8.0_191, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.5.1.el7.x86_64", arch: "amd64", family: "unix"
Method 2./ Installing Apache Maven From Source
1. Install Java
01- Java Development Kit (JDK) is required to install Apache Maven. Use the following command to Install the OpenJDK package:
# yum install java-1.8.0-openjdk
– To verify that Java was successfully installed, run the following command:
# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
2. Download Apache Maven
– Go to the official Apache Maven download page and use the wget
command to download the latest version of Apache Maven.
# wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
– When the download is completed, extract the archive in the /opt
directory like below
# sudo tar -xzvf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt
– Create a symbolic link maven
which will point to the Maven installation directory in our example is apache-maven-3.6.3
# sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
3. Setup environment variables
– Next, we’ll need to setup the environment variables. Open your text editor and create a new file named maven.sh
inside of the /etc/profile.d/
directory.
# sudo vi /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/jre-openjdk export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
– Finally, load the new environment variables by typing:
# source /etc/profile.d/maven.sh
4. Verify the installation
– To verify that Maven is successfully installed, use the mvn -version
command which will print the Maven version:
# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.5.1.el7.x86_64", arch: "amd64", family: "unix"
Conclusion
You have successfully installed Apache Maven on your CentOS 7 / RHEL 7 server.
You might want to check the following guides:
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!