How To Set up Apache Maven on AlmaLinux 8

In this tutorial, we want to teach you How To Set up Apache Maven on AlmaLinux 8.

Apache Maven is a project management software, and we can say it is a comprehension tool. It is based on the concept of the project object model (POM), Maven can manage a project’s build, reporting, and documentation from a central piece of information.

Maven simplifies and standardizes the project build process. It handles team collaboration, compilation, distribution, documentation, and separate tasks seamlessly. Maven increases reusability, and it also takes care of most of the build-related tasks. It works in helps many steps such as adding jars to the project library, building reports, and executing Junits test cases, creating Jar, War, Ear files for the project, and even many more things.

How To Set up Apache Maven on AlmaLinux 8

To install Apache Maven on AlmaLinux 8, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with AlmaLinux 8.

Now you can follow the steps below to install the latest Apache Maven version on AlmaLinux 8. We’ll be downloading the latest release of Apache Maven from their official website.

Install OpenJDK on AlmaLinux 8

Maven 3.3+ requires JDK 1.7 or above to be installed on your AlmaLinux 8.

First, update your local package index with the following command:

sudo dnf update -y

Then, use the command below to install the OpenJDK package on AlmaLinux 8:

sudo dnf install java-1.8.0-openjdk

At this point, Verify your Java installation by checking its version:

java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)

Install Apache Maven on AlmaLinux 8

You need to visit the Apache Maven downloads page and copy the link address of the binaries package. Next, use the wget command to download it on your server in the tmp directory:

wget -P /tmp

At this point, you need to extract your downloaded file in the opt directory:

sudo tar xf /tmp/apache-maven-3.8.5-bin.tar.gz -C /opt

Now you should create a symbolic link that will point to the Maven installation directory on AlmaLinux 8:

sudo ln -s /opt/apache-maven-3.8.5 /opt/maven

Note: To upgrade your Maven installation, simply unpack the newer version and change the symlink to point to it.

At this point, you should set up the Maven environment variables on AlmaLinux 8. To do this, use your favorite text editor to create a new file inside the /etc/profile.d directory:

sudo vi /etc/profile.d/

Add the following content to the file:

export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

When you are done, save and close the file.

Next, make your file executable with the following command:

sudo chmod +x /etc/profile.d/

Load the Maven environment variables on AlmaLinux 8 with the following command:

source /etc/profile.d/

At this point, you can verify your Maven installation by checking its version:

mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/maven
Java version: 1.8.0_332, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-305.3.1.el8_4.x86_64", arch: "amd64", family: "unix"

That’s it. The latest version of Apache Maven is now installed on your AlmaLinux system.


At this point, you learn to Set up Apache Maven on AlmaLinux 8.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!