Linux Tactic

Mastering Maven: A Comprehensive Guide for CentOS Users

Installing Apache Maven on CentOS with Dnf/Yum

Apache Maven is a popular build automation tool used primarily for Java projects. It helps in managing project builds, dependencies, and documentation.

In this article, we will guide you on how to install Apache Maven on your CentOS machine using the Dnf package manager.

Installing Maven using Dnf

Step 1: Log in to your CentOS machine and open the terminal. Step 2: Use the following command to update your system and install Dnf package manager:

sudo yum update

sudo yum install dnf

Step 3: Use the following command to install Apache Maven.

sudo dnf install maven

This command will download and install Maven along with all its dependencies on your system. Depending on the internet speed, the installation might take a while.

Verifying the installation

To confirm whether Apache Maven is installed correctly or not, enter the following command in the terminal. mvn -version

If the installation was successful, it will display the Maven version and the Java version used by Maven.

Installing the Latest Release of Apache Maven

If you want to install the latest release of Apache Maven on your CentOS machine, follow the below steps. Step 1: Install OpenJDK 11

Apache Maven requires the Java Development Kit (JDK) to be installed on the system.

OpenJDK 11 is the recommended version for the latest release. Use the following commands to install OpenJDK 11 on your system.

sudo yum install java-11-openjdk-devel

java -version

The second command will verify the installation of Java. Step 2: Download the Apache Maven archive

Visit the official Apache Maven website and navigate to the download page.

Choose the latest release, click on the link to download the archive file and download it. You can also use the wget command to download the archive file.

wget https://downloads.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz

Step 3: Extract the archive file

Use the following command to extract the downloaded archive file. tar -xvzf apache-maven-3.8.3-bin.tar.gz

The above command will extract the archive file to the current directory.

Step 4: Set up environment variables

To use Apache Maven, you need to set up environment variables. Open the bash profile file using the following command.

sudo gedit ~/.bash_profile

Add the below lines to the file. export M2_HOME=/path/to/apache-maven-3.8.3

export M2=$M2_HOME/bin

export PATH=$M2:$PATH

Note: Replace /path/to/ with the path where you extracted the archive file.

Save the file and close the editor. Now, reload the bash profile using the following command.

source ~/.bash_profile

Step 5:

Verifying the installation

After setting up the environment variables, enter the following command to verify the installation. mvn -version

If the installation was successful, it will display the Maven version and the Java version used by Maven.

Conclusion

In this article, we have covered the installation of Apache Maven on CentOS using the Dnf package manager and also the latest release of Apache Maven. You can choose the appropriate method based on your requirement and follow the step-by-step guide to install it on your system.

We hope this article has been informative and helpful to you. Happy coding!

In this article, we have discussed how to install Apache Maven on CentOS using the Dnf package manager and how to install the latest release of Apache Maven.

We have provided step-by-step instructions and highlighted the importance of setting up environment variables and verifying the installation using the mvn -version command. By following these instructions, users can manage their project builds, dependencies, and documentation with ease.

Apache Maven is a useful and powerful tool that can help in automating tasks, improving efficiency, and speeding up the development process. Happy coding!

Popular Posts