Skip to content
Follow
Ubuntu Linux

How to Install Apache Maven on Ubuntu Linux

Richard
Written by
Richard
Oct 20, 2021 Updated Jul 14, 2026 4 min read
How to Display Seconds on Ubuntu Top Menu Clock
How to Display Seconds on Ubuntu Top Menu Clock

Apache Maven installs on Ubuntu Linux using either the handy APT package manager or by downloading it yourself. Maven is a free tool that helps manage software projects, making the building process simpler and more organized.

It works by using a project description file, called a POM, to handle everything needed for a project, from getting necessary code libraries to building the final software.

Ubuntu’s software sources often have Apache Maven version 3.6.3 ready to go with one command, which works well for most needs. If you need the absolute latest version or features not yet available, you can install Maven manually.

⚡ Quick Answer

Install Apache Maven on Ubuntu Linux using the command `sudo apt install maven` for the version in the repositories, or manually download the latest binary from the Apache Maven website and configure environment variables. Verify the installation by running `mvn –version`.

How to install Apache Maven with apt on Ubuntu Linux

Installing Apache Maven on Ubuntu Linux uses the apt package manager. This method relies on Ubuntu’s software sources and also installs OpenJDK, a free Java platform, ensuring your system is ready for development right away.

The `apt install` command installs OpenJDK, a free, open-source Java platform, and the stable version of Apache Maven, a build automation tool. This ensures both Java and Maven are ready to build software projects on Ubuntu Linux.

🐧Bash / Shell
sudo apt update
sudo apt install maven

Run the commands above to update your Ubuntu package index and install Apache Maven, along with all dependencies like OpenJDK. This is the fastest way if you don’t need the absolute latest version of Apache Maven.

To verify the installed version, run the commands below.

💻Code
mvn --version

You should see something similar to the content below:

💻Code
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

Downloading and installing a specific or the latest Apache Maven version on Ubuntu Linux involves a manual process. Before you download Maven, make sure Java is set up by running `sudo apt update` and `sudo apt install default-jdk`.

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

🐧Bash / Shell
sudo apt update
sudo apt install default-jdk

After installing OpenJDK, continue below to get Maven installed and configured.

Apache Maven version 3.8.3 was the latest release when this post was written. Visit the Apache Maven download page to find newer versions. Downloading the latest available version is generally recommended over older ones.

Run the commands below to download version 3.8.3.

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

Then, extract the downloaded package to the /opt directory.

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

Consider creating a symbolic link to the version folder. This is useful for managing multiple versions and updating them as new ones come out. Run the commands below to link version 3.8.3 to the Maven home folder in /opt/Maven.

🐧Bash / Shell
sudo ln -s /opt/apache-maven-3.8.3 /opt/maven
💡Tip
When the next version is released, update the symbolic link to point to the new release folder. You can do this by running the command again and changing the release number in the folder name.

Setup Maven Environment Variables

After you download and unpack Maven on Ubuntu Linux, setting up environment variables is the next important step. This tells your computer where to find Maven so you can use its commands easily by editing the `maven.sh` file.

🐧Bash / Shell
sudo nano /etc/profile.d/maven.sh

Copy and paste the lines below and save them into the file.

💻Code
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 commands below to update and load the changes.

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

That should do it! Now run the commands below to check the version number.

💻Code
mvn --version

You should see the content below.

💻Code
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"

Apache Maven is a powerful tool for managing software projects.

  • Apache Maven is a powerful tool for managing software projects.
  • Installing Maven on Ubuntu is straightforward, with options to use package managers or manual installation.
  • Using the apt package manager ensures a quick setup with stable versions.
  • Manually downloading and configuring Maven is recommended for the latest features and capabilities.
  • Setting up environment variables is essential for proper Maven functionality.
  • Regularly check for updates to stay on the latest version of Maven, enhancing your project management experience.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to install Open-VM Tools on Ubuntu 24.04
Ubuntu Linux How to install Open-VM Tools on Ubuntu 24.04
How to Create a Headless VM on Ubuntu Using VirtualBox
Ubuntu Linux How to Create a Headless VM on Ubuntu Using VirtualBox
How to Set Up Environment Variables in Windows 11
Windows How to Set Up Environment Variables in Windows 11

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *