Apache Maven is an open-source project management tool used for managing Java projects. Using Maven, you can manage the project’s reporting, build, and documentation from a central place. It can also manage written projects in languages such as C#, Ruby, Scala, etc. It is based on the POM model and hosted by the Apache Software Foundation.

This post will show you how to install Apache Maven on Fedora.

Step 1 – Install Java JDK

Apache Maven is a Java-based software, so Java must be installed on your server. If not installed, you can install it using the following command.

dnf install java-11-openjdk -y

After installing Java JDK, you can verify the Java installation using the following command.

java --version

You should see the Java version in the following output.

openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment 18.9 (build 11.0.15+10)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.15+10, mixed mode, sharing)

Step 2 – Download and Install Apache Maven

First, visit the Apache Maven official website, pick the latest version of Maven, and download it with the following command.

wget https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz

Once the download is completed, extract the downloaded file with the following command.

tar -xvzf apache-maven-3.9.1-bin.tar.gz

Next, move the extracted directory to the /opt directory.

mv apache-maven-3.9.1 /opt/maven

Step 3 – Create an Environment Variable for Maven

Next, you will need to create an environment variable file and define the path of the Maven.

nano /etc/profile.d/maven.sh

Add the following lines.

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save and close the file, then activate the environment variable with the following command.

source /etc/profile.d/maven.sh

Now, verify the Apache Maven version with the following command.

mvn -version

You should see the Maven version in the following output.

Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /opt/maven
Java version: 11.0.15, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.15.0.10-1.fc34.x86_64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.12.8-300.fc34.x86_64", arch: "amd64", family: "unix"

Step 4 – Create a Project Using Maven

First, create a directory for the Maven project.

mkdir project

Next, navigate to the project directory and create a project using the following command.

cd project
mvn archetype:generate -DgroupId=com.example.app \
-DartifactId=test-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false

You should see the following output.

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /root/project
[INFO] Parameter: package, Value: com.example.app
[INFO] Parameter: groupId, Value: com.example.app
[INFO] Parameter: artifactId, Value: test-app
[INFO] Parameter: packageName, Value: com.example.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /root/project/test-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.381 s
[INFO] Finished at: 2023-04-22T02:53:57-04:00
[INFO] ------------------------------------------------------------------------

Next, navigate to the application directory and build a package for your project using the following command.

cd test-app
mvn package

You should see the following output.

[INFO] Building jar: /root/project/test-app/target/test-app-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.213 s
[INFO] Finished at: 2023-04-22T02:55:21-04:00
[INFO] ------------------------------------------------------------------------

Conclusion

In this post, we explained how to install Apache Maven on Fedora. You can now use Apache Maven with other programming languages and manage your project from the central location. In addition, you can now use Apache Maven on dedicated server hosting from Atlantic.Net!