Thursday, September 4, 2025
HomeGuest BlogsInstall Apache Maven on CentOS 7 / Fedora 37/36/35/34/33

Install Apache Maven on CentOS 7 / Fedora 37/36/35/34/33

Apache Maven is a software project management/automation tool used primarily for managing Java project’s build, reporting, and documentation from a central piece of information. This tutorial will help you to install Apache Maven on CentOS 7 / Fedora 37/36/35/34/33 Linux system.

For Ubuntu / Debian, use: Install Latest Apache Maven on Ubuntu & Debian

Step 1: Update system & Install Java

Apache Maven requires the host system to have the Java Development Kit. Install OpenJDK on CentOS 7 / Fedora:

Install Java on CentOS 7 / Fedora:

## Java 17 ###
sudo yum -y install wget lsof java-17-openjdk

## Java 11 ###
sudo yum -y install wget lsof java-11-openjdk

After the installation of Java, you can quickly confirm the version using the following command:

$ java -version
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment (Red_Hat-17.0.5.0.8-1.fc37) (build 17.0.5+8)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.5.0.8-1.fc37) (build 17.0.5+8, mixed mode, sharing)

Step 2: Download and Install Apache Maven

Check  the latest release of Apache Maven and save this to a variable:

export VER="3.8.7"

Download the latest release of Apache Maven exported above:

wget https://downloads.apache.org/maven/maven-3/${VER}/binaries/apache-maven-${VER}-bin.tar.gz

Now extract the downloaded tarball:

tar xvf apache-maven-${VER}-bin.tar.gz

Move the resulting directory to /opt

sudo mv apache-maven-${VER} /opt/maven

Setup Environment Variables to load Apache Maven

cat <<EOF | sudo tee /etc/profile.d/maven.sh
export MAVEN_HOME=/opt/maven
export PATH=\$PATH:\$MAVEN_HOME/bin
EOF

Source the file

$ source /etc/profile.d/maven.sh
$ echo $MAVEN_HOME
/opt/maven
$ echo $PATH

Your $PATH should have /opt/maven/bin at the end.

Step 3: Verify Apache Maven installation

Finally, validate that Apache Maven has been installed correctly:

$ mvn --version
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /opt/maven
Java version: 17.0.5, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.5.0.8-1.fc37.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.0.11-300.fc37.x86_64", arch: "amd64", family: "unix"

This command should print Maven version and used Java version.

All options are available on:

$ mvn -h

Create Maven projects directory:

mkdir ~/mvn-projects
cd ~/mvn-projects

Create your first project:

mvn archetype:generate -DgroupId=com.mycompany.app \
-DartifactId=my-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false

Since this is the first run,  it may take a while to execute.  This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository.

On a successful run, you should get output similar to below:

INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /root/projects
[INFO] Parameter: package, Value: com.mycompany.app
[INFO] Parameter: groupId, Value: com.mycompany.app
[INFO] Parameter: artifactId, Value: my-app
[INFO] Parameter: packageName, Value: com.mycompany.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /root/projects/my-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.301 s
[INFO] Finished at: 2018-11-18T02:26:08-05:00
[INFO] ------------------------------------------------------------------------

The generate goal created a directory with the same name given as the artifactId.

$ tree my-app/
my-app/
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── mycompany
    │               └── app
    │                   └── App.java
    └── test
        └── java
            └── com
                └── mycompany
                    └── app
                        └── AppTest.java

11 directories, 3 files

  • The src/main/java directory contains the project source code
  • The src/test/java directory contains the test source
  • The file pom.xml is the project’s Project Object Model (POM).

The filepom.xml is the core of a project’s configuration in Maven. It contains the majority of information required to build a project.

Build the Project

To build your Project, run:

mvn package

The command line will print out various actions, and end with the following:

.....
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Nov 18 10:39:20 EAT 2018
[INFO] Final Memory: 2M/6M
[INFO] ------------------------------------------------------------------------

That’s all. Check Official Maven Documentation for further learning.

You can also read:

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6748 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS