Apache Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT.
In this tutorial we will show you two different ways to install Apache Maven on CentOS 8: Using the dnf
package manager or by a source from the official website.
Prerequisites
You’ll need to be logged in as a user with sudo
privileges in order to install the Apache Maven.
Method 1./ Installing Apache Maven using dnf
01- The official CentOS repositories contains Maven packages that can be installed with the dnf
package manager. Use the below command:
# sudo dnf install maven
02- To verify if Apache Maven is successfully installed just run the mvn -version
command:
# mvn -version
Apache Maven 3.0.5 (Red Hat 3.0.5-17)
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.7.10-1.el8_1.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-147.8.1.el8_1.x86_64", arch: "amd64", family: "unix"
Method 2./ Installing Apache Maven From Source
1. Install Java
2. Download Apache Maven
01- First, go to the official Apache Maven download page and use the wget
command to download the latest version of Apache Maven.
# wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
02- When the download is completed, extract the archive in the /opt
directory like below
# sudo tar -xzvf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt
03- Next, create a symbolic link maven
which will point to the Maven installation directory in our example is apache-maven-3.6.3
# sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
3. Setup environment variables
01- First, we’ll need to setup the environment variables. So, open your text editor and create a new file named maven.sh
inside of the /etc/profile.d/
directory.
# sudo vi /etc/profile.d/maven.sh export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
02- Finally, load the new environment variables by typing:
# source /etc/profile.d/maven.sh
4. Verify the installation
– To verify that Maven is successfully installed, use the mvn -version
command which will print the Apache Maven version:
# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 11.0.7, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.7.10-1.el8_1.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-147.8.1.el8_1.x86_64", arch: "amd64", family: "unix"
Conclusion
You have successfully installed Apache Maven on your CentOS 8 server.
You might want to check the following guides:
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!