Atlantic.Net Blog

How to Install Apache Maven on Oracle Linux 8

Apache Maven is a free, open-source, POM-based Java project management tool. It is written in Java and used to build projects written in C#, Scala, Ruby, etc. Apache Maven is designed for Java developers to help them to develop reports, check, build and test automation setups. The tool was developed by the Apache Group to build, publish, and deploy multiple Java projects at once for better performance. Apache Maven uses XML files to define configuration details, project dependencies, and other data.

Features

  • Dependency management
  • Large repository
  • Extensible via plug-ins
  • Model-based builds
  • Release management and distribution publication
  • Backward compatibility
  • Easy to test, deploy and manage upgrades

In this post, we will show you how to install Apache Maven on OracleLinux 8.

Step 1 – Install Maven via AppStream Repository

By default, the Apache Maven package is included in the OracleLinux AppStream repository. You can check it using the following command:

dnf info maven

You should get the following output:

Last metadata expiration check: 1:43:10 ago on Thursday 19 May 2022 02:02:55 AM EDT.
Available Packages
Name         : maven
Epoch        : 1
Version      : 3.5.4
Release      : 5.module+el8+5161+5cac467c
Architecture : noarch
Size         : 27 k
Source       : maven-3.5.4-5.module+el8+5161+5cac467c.src.rpm
Repository   : ol8_appstream
Summary      : Java project management and project comprehension tool
URL          : http://maven.apache.org/
License      : ASL 2.0 and MIT
Description  : Maven is a software project management and comprehension tool. Based on the
             : concept of a project object model (POM), Maven can manage a project's build,
             : reporting and documentation from a central piece of information.

Now, install Apache Maven using the following command:

dnf install maven -y

After the installation, verify the Maven version using the following command:

mvn --version

You should get the following output:

Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_332, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-348.12.2.el8_5.x86_64", arch: "amd64", family: "unix"

Step 2 – Install Maven From Source

It is a good idea to install Apache Maven from the source if you want to install the latest version of Maven. Apache Maven is Java-based software. so you will need to install OpenJDK on your system.

Run the following command to install Java on your server.

dnf install java-11-openjdk -y

After the successful installation, verify the Java version using the following command:

java --version

Sample output:

openjdk 11.0.15 2022-04-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.15+10-LTS, mixed mode, sharing)

Next, go to the Apache Maven download page and download the latest version of Maven using the wget command:

wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz

Next, create a directory for Apache Maven with the following command:

mkdir /usr/local/maven

Next, extract the downloaded file to the Maven directory with the following command:

tar xzf apache-maven-3.8.5-bin.tar.gz -C /usr/local/maven/ --strip-components=1

Next, you will need to add the Maven binary location to the system path. You can add it with the following command:

echo export 'PATH=$PATH:/usr/local/maven/bin/' > /etc/profile.d/maven.sh
echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.15.0.10-2.el8_6.x86_64' >> /etc/profile.d/maven.sh

Next, set proper permissions to the maven.sh file with the following command:

chmod +x /etc/profile.d/maven.sh

Next, activate the Maven system path with the following command:

source /etc/profile.d/maven.sh

Next, verify the Maven version using the following command:

mvn --version

You should get the following output:

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/local/maven
Java version: 11.0.15, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.15.0.10-2.el8_6.x86_64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-348.12.2.el8_5.x86_64", arch: "amd64", family: "unix"

Conclusion

In the above guide, we explained two methods to install Apache Maven on OracleLinux 8. You can now start using Apache Maven to manage your Java project. Get started on VPS hosting from Atlantic.Net.

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year