Apache Maven is a powerful project management utility that uses the idea of project object model. It manages the project's build, dependency, reporting, and documentation.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Apache queries on Linux Systems.
In this context, we shall look into the different method and process of Installing Apache Maven on CentOS.
Previously, we mentioned how to Install Apache Maven on Ubuntu OS.
Methods of Installing Apache Maven on CentOS
Here, you will learn the best methods to install Apache Maven on your system:
- Apache Maven Installation via Yum Package Manager.
- Apache Maven Installation via Direct Download method.
1. Apache Maven Installation via Yum Package Manager
Apache Maven is included in the CentOS default repository. Here, we are going to install Apache Maven on CentOS via the Yum package manager.
So follow the steps given below to do this.
i. Execute the command given below in the Terminal to install Apache Maven on your CentOS system:
$ sudo yum install maven
You might be prompted to enter sudo password, after which the installation of Apache maven will be started.
ii. After the Apache Maven is installed, you can confirm it using this command:
$ mvn --version
This will display the version of Apache Maven installed on the system.
2. Apache Maven Installation via Direct Download method
Apache Maven is also available for download and installation on its official website. Here, we are going to install Apache Maven on the CentOS system. Using this method, you can have the latest release of Maven. Note that we are going to download the current latest version 3.8.1 (as of July 2021). So follow the steps outlined below.
i. Apache maven requires JDK 1.7 or later to be installed on your machine. To verify if Java is installed, run the command below:
$ java --version
If it installed, the output will display the Java version available on the system.
Otherwise, you can install it using the command below in the Terminal:
$ sudo yum install -y java-1.8.0-openjdk-devel
ii. Now, Visit the Apache Maven Downloads page and download the latest or any previous version of Apache Maven. You can also use this command for downloading the Maven 3.8.1:
$ wget https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
The downloaded file will be an archive file.
iii. Extract the downloaded Apache Maven archive using the command below:
$ sudo tar xf apache-maven-3.8.1-bin.tar.gz -C /opt
Replace the apache-maven-3.8.1 with your extracted directory name.
This command will extract the archive in a directory named apache-maven-3.8.1 (apache-maven-version_number) in the /opt directory.
iv. Move inside the /opt directory and rename the extracted directory as follows:
$ cd /opt
$ sudo mv apache-maven-3.8.1/ apache-maven
v. Now setup environment variable. To do so, create a file maven.sh in the /etc/profile.d using the command below:
$ sudo nano /etc/profile.d/maven.sh
Now copy-paste the below lines in the maven.sh file:
Then save the file and exit the editor.
vi. The maven.sh file created in the previous step is a script file. You will have to make it executable as follows:
$ sudo chmod +x /etc/profile.d/maven.sh
vii. Apply the configurations as follows:
$ source /etc/profile.d/maven.sh
Now the Apache Maven has been installed. To verify the installation, use the command below:
$ mvn --version
The output will verify the Apache maven version installed in the system.
How to Uninstall Apache Maven from CentOS system ?
If you want to remove Apache Maven from your system, you can do so using the command below in the Terminal:
$ sudo yum remove maven
[Need help in Installing Software Packages on CentOS system? We can help you. ]