Apache Maven is a free, open-source, and extremely popular build management tool for Java projects. It is based on the Project Object Model and contains XML files to define configuration details, project dependencies, and other data. It is designed to help Java developers build projects by proficiently documenting and reporting important project-related information.
Features
- All configuration is managed from a single XML file.
- Easy to test and deploy.
- Easy to manage upgrades.
- Occupies less space than other project management tools.
- Reduces multiple dependencies and eliminates duplicates.
In this post, we will show you how to install Apache Maven on Rocky Linux 8.
Step 1 – Install Maven via AppStream Repository
By default, the Maven package is included in the Rocky Linux AppStream repository. You can check it using the following command:
dnf info maven
You should get the following output:
Name : maven Epoch : 1 Version : 3.5.4 Release : 5.module+el8.3.0+133+b8b54b58 Architecture : noarch Size : 26 k Source : maven-3.5.4-5.module+el8.3.0+133+b8b54b58.src.rpm Repository : appstream Summary : Java project management and project comprehension tool URL : http://maven.apache.org/ License : ASL 2.0 and MIT Description : Maven is a software project management and comprehension tool. Based on the : concept of a project object model (POM), Maven can manage a project's build, : reporting and documentation from a central piece of information.
Now, install the Apache Maven using the following command:
dnf install maven -y
After the installation, verify the Maven version using the following command:
mvn --version
You should get the following output:
Apache Maven 3.5.4 (Red Hat 3.5.4-5) Maven home: /usr/share/maven Java version: 11.0.12, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-305.10.2.el8_4.x86_64", arch: "amd64", family: "unix"
Step 2 – Install Maven From Source
If you want to install the latest version of Maven then you can install it from the Maven source. First, install the Java package with the following command:
dnf install java-11-openjdk -y
Once Java is installed, verify the Java version using the following command:
java --version
Sample output:
openjdk 11.0.12 2021-07-20 LTS OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)
Next, download the latest version of Maven from their official website:
wget https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
Next, create a directory for Apache Maven with the following command:
mkdir /usr/local/maven
Next, extract the downloaded file to the Maven directory with the following command:
tar xzf apache-maven-3.8.1-bin.tar.gz -C /usr/local/maven/ --strip-components=1
Next, you will need to add the Maven binary location to the system path. You can add it with the following command:
echo export 'PATH=$PATH:/usr/local/maven/bin/' > /etc/profile.d/maven.sh echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64' >> /etc/profile.d/maven.sh
Next, set proper permissions to the maven.sh file with the following command:
chmod +x /etc/profile.d/maven.sh
Next, activate the Maven system path with the following command:
source /etc/profile.d/maven.sh
Next, verify the Maven version using the following command:
mvn --version
You should get the following output:
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: /usr/local/maven Java version: 11.0.12, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64 Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-305.7.1.el8_4.x86_64", arch: "amd64", family: "unix"
Conclusion
In the above guide, we explained how to install Apache Maven on RockyLinux 8 using two methods. You can now use Apache Maven to manage your Java project – try it on dedicated server hosting from Atlantic.Net!