Apache Maven is a powerful project management and comprehension tool used by software developers working with the Java programming language. It is a build automation tool that favors convention over configuration, and is based on the concept of a project object model (POM). Maven follows some fundamental concepts which make it superior to its predecessor, Make.
Prerequisites
Before we dive into the installation process, there are a few prerequisites that need to be met:
- A server running AlmaLinux 8.
- Root access on the server.
Updating the System
To ensure that your system is up to date and free from any security vulnerabilities, it is important to regularly update your packages. Use the following commands to update your system:
sudo dnf update -y sudo dnf upgrade -y
Installing Java
Maven is written in Java, so it is necessary to have Java installed on your system before installing Maven. To install the open-source version of Java Development Kit (JDK) and Java Runtime Environment (JRE), run the following command:
sudo dnf install java-11-openjdk-devel -y
Verify the installation by checking the Java version:
java-version
Installing Maven Via DNF
The easiest way to install Maven on AlmaLinux 8 is by using the DNF package manager. The official AlmaLinux repositories already contain the Maven package, so you don’t need to add any external repositories. Run the following command to install Maven:
sudo dnf install maven -y
To verify that Maven has been successfully installed, run the following command:
mvn-version
Installing Apache Maven from Source
If you prefer to install the latest stable version of Maven, you can do so by installing it from the source code. This method requires downloading the source code, building Maven, and then installing it on your system.
First, download the latest stable version of Apache Maven from the official Maven website. Use the following command to download the source code:
wget https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz
Once the download is complete, extract the archive to the /opt/ directory using the following command:
sudo tar -xvf apache-maven-3.8.3-bin.tar.gz -C /opt sudo ln -s /opt/apache-maven-3.8.3 /opt/maven
To add the Maven installation directory to the PATH environment variable, create a new script file:
sudo nano /etc/profile.d/maven.sh
Add the following lines 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}
Save the file and exit the text editor. Make the script executable and load the environment variables for the current session with the following command:
sudo chmod +x /etc/profile.d/maven.sh && source /etc/profile.d/maven.sh
Verify the installation by running the following command:
mvn-version
Conclusion
In this article, we have covered two methods of installing Apache Maven on AlmaLinux 8: using the DNF package manager and installing from the source code. Both methods provide you with the flexibility to choose the installation that best suits your needs.
Remember to regularly update your system and keep it secure by installing the latest updates. Maven is a powerful tool that simplifies project management and build automation for Java developers. Whether you choose to install it via DNF or from the source, Maven will enhance your development workflow and make your projects more efficient.
If you found this article helpful, please share it with others. If you have any questions or feedback, feel free to leave a comment below.
This article is brought to you by Shape.host, a leading provider of Linux SSD VPS hosting services. With Shape.host, you can enjoy reliable and scalable cloud hosting solutions for your business. Visit Shape.host for more information.