In this short guidance, we will learn how to install Apache Maven version 3.6.3 on CentOS 8 operating system. Apache Maven is a software project management and build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project.
In this tutorial we will use Apache Maven version 3.6.3 which was released on 25 November 2019.
Maven Installation
The Apache Maven installation steps will be described on several steps.
- Prerequisite
- Download Maven source and extract files
- Set up environment variables
- Verify Apache Maven Installation
The details of installation will be detail discussed below.
1. Prerequisites
Apache Maven requires any system requirements :
- Java Development Kit (JDK) Maven 3.3+ require JDK 1.7
- CentOS 8 system with disk capacity about 500MB
- User account with sudo privilege.
If we have no Java installed on our system, we have to install it first. The Java installation on CentOS 8 has been discussed Install Java (Open JDK 11) on CentOS 8 article.
$ java -version
Output :
[ramans@otodiginet ~]$ java -version openjdk version "11.0.8" 2020-07-14 LTS OpenJDK Runtime Environment 18.9 (build 11.0.8+10-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode, sharing)
2. Download Maven Source and Extract Files
The first step to install Apache Maven is to download the source files from the Maven official website. By using wget command line, we will download the Apache Maven source file. In this tutorial, we will use Apache Maven versin 3.6.3.
$ wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
Output :
[ramans@otodiginet ~]$ wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz --2021-01-21 15:00:09-- https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 2a01:4f8:10a:201a::2 Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 9506321 (9.1M) [application/x-gzip] Saving to: ‘apache-maven-3.6.3-bin.tar.gz’ apache-maven-3.6.3-bin.tar.gz 100%[==============================================>] 9.07M 856KB/s in 14s 2021-01-21 15:00:25 (664 KB/s) - ‘apache-maven-3.6.3-bin.tar.gz’ saved [9506321/9506321]
After the download process is complete, then we will extract the file and move it to a new created directory, named it as /opt/maven.
$ tar -zxvf apache-maven-3.6.3-bin.tar.gz $ sudo mkdir /opt/maven $ sudo mv apache-maven-3.6.3
Output :
[ramans@otodiginet ~]$ tar -zxvf apache-maven-3.6.3-bin.tar.gz apache-maven-3.6.3/README.txt apache-maven-3.6.3/LICENSE apache-maven-3.6.3/NOTICE apache-maven-3.6.3/lib/ apache-maven-3.6.3/lib/cdi-api.license apache-maven-3.6.3/lib/commons-cli.license apache-maven-3.6.3/lib/commons-io.license apache-maven-3.6.3/lib/commons-lang3.license . . . apache-maven-3.6.3/lib/wagon-file-3.3.4.jar apache-maven-3.6.3/lib/maven-resolver-connector-basic-1.4.1.jar apache-maven-3.6.3/lib/maven-resolver-transport-wagon-1.4.1.jar apache-maven-3.6.3/lib/maven-slf4j-provider-3.6.3.jar apache-maven-3.6.3/lib/jansi-1.17.1.jar
[ramans@otodiginet ~]$ sudo mkdir /opt/maven [sudo] password for ramans: [ramans@otodiginet ~]$ sudo mv apache-maven-3.6.3 /opt/maven
3. Set up Environment Variables
On this step, we will set the environment variables for Maven by creating a maven.sh file under /etc/profile.d/ directory.
We will add the following line.
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.9.11-3.el8_3.x86_64/ export M2_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
The JAVA_HOME and M2_HOME variables will depend on JDK and Maven installation. After all are set, then we will load the environment variables in the current shell using the following command.
# source /etc/profile.d/maven.sh
Output :
root@otodiginet ~]# source /etc/profile.d/maven.sh
4. Verify Maven Installation On CentOS 8
The final steps is to check whether the Apache Maven has been successfully configured on your system. For this purpose we will use the following command.
# mvn -version
Output :
[root@otodiginet ~]# mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /opt/maven Java version: 11.0.9.1, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.9.11-3.el8_3.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-193.el8.x86_64", arch: "amd64", family: "unix"

Conclusion
In this short tutorial, we have learnt how to install Apache Maven version 3.6.3 on CentOS 8 operating system successfully. I hope this tutorial will be helpful.