18.5 C
Senior Writer and partner

How to install Apache Maven on Ubuntu 18.04 / Debian 9?

One of the things I like best for Java development is that there are many tools for it. Some of them become vital day by day. Others not so much, but help too much to complete the process. With this in mind, today I will teach you how to install Apache Maven on Ubuntu 18.04. This tutorial is also applicable to Debian 9.

To manage projects done in Java, there is no better tool than Apache Maven. This fantastic tool, belonging to the Apache foundation, comes with predefined objectives to perform certain clearly defined tasks, such as code compilation and packaging.

There are many features that make Maven a great tool. However, the key is that Maven is ready for network use. In addition, its functions are made extensible by the ability to install plugins. Finally, Maven relies on the Project Object Model (POM) to describe the project, as well as its dependencies for later deployment.

So, let’s start to install Apache Maven.

1. Upgrade the system

- Advertisement -

First of all, I recommend you to update the system. You should always do this frequently. So open a terminal and run.

:~$ sudo apt update && sudo apt upgrade

1.- Upgrade the system
1.- Upgrade the system

Note: Your user must be able to use sudo.

Now you’ll have a more stable and secure system.

2. Install Oracle Java

Apache Maven requires Java for its operation. It does so because it is made with this programming language, so you will have to install it. However, don’t worry because here I show you how to do it in an easy and simple way.

2.- Check the java version
2.- Check the java version

Once you have finished installing Java, you will be able to continue.

3. Install Apache Maven

First option: Installing Maven using APT

There are two ways to install Apache Maven. The first and simplest is to do it through the main repositories of Ubuntu and Debian, that is, just enough:

:~$ sudo apt install maven

And that’s it.

This method is the simplest, but it has the main problem, the latest version of Maven is not installed. This is because repositories freeze versions of programs for stability.

Second Option: From the source code

In this process, we’ll do a few more steps, but we’ll always have the latest version available. If you work with Java you will know that there are always new features in each release and thus be able to take better advantage of its potential.

So, let’s do it. Just run:

:~$ wget -c https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz

3.- Download and install Apache Maven
3.- Download and install Apache Maven

Note: At the time of writing this post, the latest stable version is 3.6.0.

Then, decompress it.

:~$ tar -zxvf apache-maven-3.6.0-bin.tar.gz

4.- Decompressing the file
4.- Decompressing the file

Now, move the folder to /opt.

:~$ sudo mv apache-maven-3.6.0 /opt/maven

5.- Installing apache maven
5.- Installing Apache Maven

It is now necessary to set the environment variables. Create a file called maven.sh in /etc/profile.

:~$ sudo nano /etc/profile.d/maven.sh

And add the following lines.

export JAVA_HOME=/usr/lib/jvm/java-11-oracle
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Note: The JAVA_HOME variable can be obtained with the command update-java-alternatives -l.

6.- Finding the Java path
6.- Finding the Java path

Finally, run:

:~$ source /etc/profile.d/maven.sh

Finally, check the Maven version.

:~$ mvn -version

7.- Check the Maven version
7.- Check the Maven version

And that’s it.


Apache Maven is a very important tool in the development of projects, especially if they are Java. Its installation is not difficult but its benefits are many.

Please share this post with your friends.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article