Apache Maven is an open source project management tool, mainly used for Java projects. Maven uses a project object model (POM), which is a basic XML information that contains project information, configuration details, project dependencies, and so on.
In this guide, we will explain how to install Apache Maven on CentOS 8.
The standard CentOS software source contains the Maven package, which can be installed through the dnf
package management tool. This is the easiest way to install Maven on CentOS systems. In any case, the Maven software version included in the software source will definitely lag behind the latest version of Maven. We will also show you how to download the binary installation package from their official website to install the latest version of Maven.
Choose the installation method that suits you best.
First, log in to the system as root or another user with sudo permission, and then execute the following instructions.
Installation using dnf
on CentOS 8 is very simple and straightforward.
sudo dnf install maven
mvn -version
command to verify the installed version:mvn -version
The output should look like this:
Apache Maven 3.5.4(Red Hat 3.5.4-5)
Maven home:/usr/share/maven
Java version:1.8.0_232, vendor: Oracle Corporation, runtime:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el8_0.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name:"linux", version:"4.18.0-80.7.1.el8_0.x86_64", arch:"amd64", family:"unix"
that's it. Maven has been installed on your CentOS system, and you can start using it.
In this section, we will provide step-by-step instructions to teach you how to install the latest version of Apache Maven on CentOS 8.
Maven 3.3+ requires JDK 1.7 or higher to be installed.
Enter the following command to install OpenJDK 11:
sudo dnf install java-11-openjdk-devel
Run the following command to verify that Java has been successfully installed.
java -version
The output should look like this:
openjdk version "11.0.5"2019-10-15 LTS
OpenJDK Runtime Environment 18.9(build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM 18.9(build 11.0.5+10-LTS, mixed mode, sharing)
At the time of writing this article, the latest version of Apache Maven is 3.6.3
. Please check Maven download page to check if there is a newer version.
Use the wget command to download Apache Maven to the /tmp
directory:
wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
Once the download is complete, unzip the compressed package to the /opt
directory:
sudo tar xf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt
To make it easier to control the Maven version and upgrade, we will create a virtual link maven
pointing to the Maven installation directory:
sudo ln -s /opt/apache-maven-3.6.3/opt/maven
To upgrade your Maven, you can simply unzip the updated version of Maven and modify the virtual link point.
Next, we need to set environment variables. Open your text editor and create a new file named mavenenv.sh
in the /etc/profile.d/
directory:
sudo nano /etc/profile.d/maven.sh
Paste the code below:
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Save and close the file. This script will be executed when the shell starts.
Make the script executable by running the chmod
command:
sudo chmod +x /etc/profile.d/maven.sh
Use the source
command to load environment variables:
source /etc/profile.d/maven.sh
To verify the Maven software installation, use the mvn -version
command, it will print out the Maven version:
mvn -version
You will see output similar to the following:
Apache Maven 3.6.3(cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home:/opt/maven
Java version:11.0.5, vendor: Oracle Corporation, runtime:/usr/lib/jvm/java-11-openjdk-11.0.5.10-0.el8_0.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name:"linux", version:"4.18.0-80.7.1.el8_0.x86_64", arch:"amd64", family:"unix"
that's it. The latest version of Maven has been installed on your CentOS system.
We have shown you how to install Apache Maven on CentOS 8. You can browse Apache Maven Documentation Page to learn how to start using Maven.
Recommended Posts