Developing an application requires certain tools that help us to improve creation and coding times. In the case of Java, one of them is Maven. This tool provides us with a whole set of utilities for the administration of a Java project. So, today you will learn how to install Apache Maven on CentOS 9 Stream.
Introduction—What is Apache Maven?
Apache Maven is a tool for managing and understanding software projects. Based on the Project Object Model (POM) concept, Maven can manage the building, reporting, and documentation of a project from a central piece of information.
Thanks to Maven, we will be able to define rules for compiling, packaging, testing, installing and distributing our projects all from a single configuration file. As it could not be otherwise, Apache Maven is open source and although it is quite popular in Java, we can use it for other programming languages as well.
Let’s get started.
Installing Apache Maven on CentOS 9 Stream
Before we start, we have to start with the Java installation because Maven is built in this language.
Install Java on CentOS 9 Stream
The first thing we need to do is to install Java on the system. This can be done by opening a terminal and executing this script.
sudo dnf update
sudo dnf install java-11-openjdk
After this, you can check the installed version with the following command
java -version
openjdk version "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)
With Java ready, we can continue with Maven.
Getting Apache Maven on CentOS 9 Stream
At the time of writing this post, the latest stable version of Maven is 3.8.5
which is the one we are going to install. To do so, locate yourself in the /opt
directory.
cd /opt
Then, download the Apache Maven binary
wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
--2022-05-31 20:26:34-- https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8673123 (8.3M) [application/x-gzip]
Saving to: ‘apache-maven-3.8.5-bin.tar.gz’
apache-maven-3.8.5-bin.tar.gz 100%[=====================================================================================>] 8.27M --.-KB/s in 0.07s
2022-05-31 20:26:35 (122 MB/s) - ‘apache-maven-3.8.5-bin.tar.gz’ saved [8673123/8673123]
Thereafter, unzip it
sudo tar xzf apache-maven-3.8.5-bin.tar.gz
Rename the folder as maven
by making a symbolic link out of it.
sudo ln -s apache-maven-3.8.5 maven
Next, we have to define the environment variables so that Maven can work properly:
sudo nano /etc/profile.d/maven.sh
And at the end of the file, add the following:
export M2_HOME=/opt/maven
export PATH=$${{M2_HOME}/bin:${PATH}
Save the changes and close the editor.
Apply the changes:
source /etc/profile.d/maven.sh
And now yes, check the Apache Maven version
mvn --version
This means that Apache Maven is installed.
Conclusion
In this post, we have helped you with Apache Maven. Now you know how to install it on CentOS 9 Stream, and it is a wonder to behold. I hope you can take full advantage of it in your projects.