Apache Maven is a powerful project management tool that is based on POM (project object model). Maven is a tool that can be used for building and managing any Java-based project. Maven contains XML files also referred to as pom.xml which include configuration details, project dependencies, and other data.
This article will show two different ways to install Apache Maven on CentOS 8 and other versions of CentOS.
I. Install Maven on CentOS
Installation of Java: Updating the package index
sudo yum update
- Install the OpenJDK package:
# sudo yum install java-11-openjdk-devel
- Verifying the java installation:
# java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode, sharing)
Apache Maven Download
- Install "wget" package:
# sudo yum install wget
- Download the stable version of Apache Maven and you can download it to the "/tmp" directory, as shown below:
# sudo wget https://mirrors.ibiblio.org/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
- The file will be downloaded as a .tar.gz file. You can extract it to the "/opt" directory by using the command:
# sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
In order to have control of Maven versions and updates, we will create a symbolic link to Maven that points to the Maven installation directory
Changing the symlink to point to the newer version is all that is needed to upgrade your Maven installation.
# sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
Setup the Environment for Maven
You need to configure a few environment variables, including JAVA_HOME, M3_HOME, and MAVEN_HOME.
- Create a new file named
# sudo vi /etc/profile.d/maven.sh
- The configuration below needs to be added to this newly created file:
Save and close the file.
Provide the required privileges to the file using the command below:
# sudo chmod +x /etc/profile.d/maven.sh
- Load the environment variables using the
# source /etc/profile.d/maven.sh
Verify the Maven installation
Use the command
mvn -versionwhich will print the Maven version:
# mvn -version
Apache Maven 3.6.3 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /opt/maven
Java version: 11.0.17, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-188.8.131.52.8-2.el8.x86_64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-358.el8.x86_64", arch: "amd64", family: "unix"
II. Install Apache Maven Using yum
- Easy and simple to install Maven using Yum. Initially, update the package index by using the following command
# sudo yum update
- Install Maven by using the following command
# sudo yum install maven
- Verify the installation by running the
# mvn -version