How to install Apache Maven on CentOS 8

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.

1. Prerequisites Maven

First, log in to the system as root or another user with sudo permission, and then execute the following instructions.

2. Use Dnf/Yum to install Apache Maven on CentOS

Installation using dnf on CentOS 8 is very simple and straightforward.

  1. Run the following command in the terminal to install Maven:
sudo dnf install maven
  1. Run the 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.

Three, install the latest version of Apache Maven

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.

3.1. Install OpenJDK

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)

3.2. Download Apache Maven

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.

3.3. Set environment variables###

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

3.4 Verify installation###

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.

Four, summary

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

How to install Apache Maven on CentOS 8
How to install Apache on CentOS 8
How to install Apache Kafka on CentOS 7
How to install Apache Maven on Ubuntu 20.04
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install Apache on Ubuntu 20.04
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Apache on Ubuntu 20.04
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
Maven install on centos7
[Graphic] How to install tomcat on centos
R&D: How To Install Python 3 on CentOS 7
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install and configure VNC on CentOS 8
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8