Site icon WPDig.com

How to install Apache Maven on Ubuntu Linux

This post shows students and new users how to install Apache Maven on Ubuntu Linux. Apache Maven is an open source software project management and understanding tool.

Based on the concept of a project object model (POM), Maven can help you manage the entire process of building a project, including storing documents, reports, and more.

Installing Apache Maven on Ubuntu is pretty easy and straightforward. In fact, the Maven packages are in the default Ubuntu repositories. You can run apt get commands to install it easily.

However, the versions of the Ubuntu repositories may not necessarily be the most recent. If you want to install the latest version, you may need to download and install it yourself.

Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.

Below are the two options for installing Apache Maven on Ubuntu Linux. Either should work fine, however if you want to install the latest version then option # 2 (manual download) Maven should be what you want.

How to install Apache Maven with apt on Ubuntu Linux

As mentioned above, Apache Maven is available in the default Ubuntu repositories. To install a stable version on Ubuntu Linux, run the following commands.

This command will install OpenJDK along with the stable version of Maven.

sudo apt update
sudo apt install maven

The above commands update the Ubuntu package index and install Apache Maven along with all dependencies, including OpenJDK. This is the fastest and easiest if you don’t mind getting the latest version of Apache Maven.

To check the installed version, run the following commands

mvn --version

You should see something similar to the content below:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.2, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"

How to download and install Maven on Ubuntu Linux

If you want to download the latest version or a particular version, download Maven and install it yourself. You will need to install OpenJDK first, then install and configure Apache Maven to use it.

Run the following commands to install OpenJDK on Ubuntu Linux. This will install the current stable version of OpenJDK for Ubuntu Linux.

sudo apt update
sudo apt install default-jdk

After installing OpenJDK, continue below to install and configure Maven.

At the time of writing this post, the latest version of Apache Maven is 3.8.3. Be sure to check the Maven download page to see if a newer version is available for download. If there are, select them and download them instead.

Run the following commands to download the version 3.8.3

cd /tmp
wget https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz

Then run the following commands to extract the downloaded package to the /to opt directory.

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

If you want to have standalone versions and update as they become available, create a symbolic link to the version folder. Run the following commands to link the version 3.8.3 to the Maven home folder at / opt / maven.

sudo ln -s /opt/apache-maven-3.8.3 /opt/maven

When the next version is released. all you have to do is update the symbolic link to refer to the new release folder by running the above command and updating the release number in the folder name.

Set Maven environment variables

After downloading and extracting the Maven package, go ahead and set your environment variables. To do that, run the following commands:

sudo nano /etc/profile.d/maven.sh

Then copy and paste the lines below and save them to the file.

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

Finally, run the following commands to update and load the changes.

sudo chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh

You should do that! Now run the following commands to check the version number.

mvn --version

You should see the content below.

Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /opt/maven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-37-generic", arch: "amd64", family: "unix"

Conclusion:

In this tutorial we have seen how to install Apache Maven on Ubuntu Linux. If you find any errors above or have something to add, use the comment form below.

Exit mobile version