Atlantic.Net Blog

How to Install Apache Maven on Debian 11

Hitesh Jethva
by Atlantic.Net (345 posts) under Dedicated Server Hosting, Tutorials
0 Comments

Apache Maven is an open-source automation tool that allows you to automate and simplify software development processes. It is also known as a build management system and is used to create and manage projects written in C#, Ruby, Scala, and other programming languages. It is used by many developers to manage all stages of the software development lifecycle.

In this post, we will show you how to install Apache Maven on Debian 11.

Prerequisites

  • A server running Debian 11 on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Debian 11 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Java

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

apt-get install default-jdk -y

After the successful installation, verify the Java installation using the command below:

java -version

You should see the Java version in the following output:

openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.13+8-post-Debian-1deb11u1, mixed mode, sharing)

Step 3 – Install Apache Maven

First, run the wget command to download the latest version of Apache Maven:

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

You will get the following output:

HTTP request sent, awaiting response... 200 OK
Length: 9046177 (8.6M) [application/x-gzip]
Saving to: ‘apache-maven-3.8.4-bin.tar.gz’

apache-maven-3.8.4-bin.tar.gz       100%[=================================================================>]   8.63M  --.-KB/s    in 0.1s    

2021-12-05 10:40:12 (61.4 MB/s) - ‘apache-maven-3.8.4-bin.tar.gz’ saved [9046177/9046177]

Once the download is completed, extract the downloaded file using the command below:

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

Next, move the extracted directory to /opt with the following command:

mv apache-maven-3.8.4 /opt/maven

Step 4 – Setup Environment Variables for Maven

Next, you will need to set Java environment variables for Maven. You can set them by creating a file in the /etc/profile.d/ directory:

nano /etc/profile.d/maven.sh

Add the following lines based on your Java installation path:

export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save and close the file, then load the environment variable using the following command:

source /etc/profile.d/maven.sh

Step 5 – Verify Apache Maven Installation

At this point, Apache Maven is installed on your system. You can now verify the Apache Maven installation using the command below:

mvn -version

You should see the following output:

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /opt/maven
Java version: 11.0.13, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.10.0-8-amd64", arch: "amd64", family: "unix"

Step 6 – Create a Project with Maven

Now, open your command-line terminal interface and run the following command to create your first Maven project:

mvn archetype:generate -DgroupId=com.example.app -DartifactId=testapp -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

You will get the following output:

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example.app
[INFO] Parameter: artifactId, Value: testapp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.example.app
[INFO] Parameter: packageInPathFormat, Value: com/example/app
[INFO] Parameter: package, Value: com.example.app
[INFO] Parameter: groupId, Value: com.example.app
[INFO] Parameter: artifactId, Value: testapp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Project created from Archetype in dir: /root/testapp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.503 s
[INFO] Finished at: 2021-12-06T04:01:38Z
[INFO] ------------------------------------------------------------------------

Next, navigate to your project directory and compile the application using the command below:

cd testapp
mvn package

You will get the following output:

[INFO] Building jar: /root/testapp/target/testapp-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.623 s
[INFO] Finished at: 2021-12-06T04:02:22Z
[INFO] ------------------------------------------------------------------------

Now, run the following command to test your Jar file:

java -cp target/testapp-1.0-SNAPSHOT.jar com.example.app.App

You should see the following output:

Hello World!

Conclusion

Congratulations! You have successfully installed Apache Maven on Debian 11. You can now use Apache Maven in your development environment to speed up your application development process. Try it on dedicated hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Python 3.10 on Rocky Linux 8
How to Install TaskBoard on Rocky Linux 8
How to Set Up Pritunl VPN Server on Rocky Linux 8
How to Install Teampass Password Manager on Rocky Linux 8
How to Install and Configure RabbitMQ Server on Rocky Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources