Java

How to install Maven 3 on Ubuntu 1804170416101604 LTS1510150414101404 LTS13101304 by using apt-get closed

25 September 2026 · 6 min read

How to install Maven 3 on Ubuntu 1804170416101604 LTS1510150414101404 LTS13101304 by using apt-get closed

Streamlining your development workflow on Ubuntu requires robust tools, and Apache Maven stands out as a powerful build automation and project management tool, especially vital for Java-based projects. This comprehensive guide provides a step-by-step approach to installing Maven 3 on various Ubuntu versions using the apt-get package manager. Whether you’re running Ubuntu 18.04, 16.04 LTS, or even older versions like 14.04 LTS, this tutorial has you covered. Mastering Maven installation empowers you to efficiently manage dependencies, build processes, and overall project structure, paving the way for smoother and more productive development experiences.

Preparing Your System

Before diving into the Maven installation, ensure your Ubuntu system is up-to-date. This is crucial for avoiding potential conflicts and ensuring a smooth installation process. Open your terminal and execute the following commands:

  1. sudo apt-get update
  2. sudo apt-get upgrade

These commands refresh the local package index and upgrade any outdated packages on your system. This foundational step sets the stage for a hassle-free Maven installation.

Installing Java

Maven requires Java to function. If you don’t already have Java installed, install the default OpenJDK (Java Development Kit) using apt-get:

sudo apt-get install default-jdk

Verify the Java installation by running: java -version. This should display the installed Java version, confirming a successful installation.

Installing Maven 3 via apt-get

Now, let’s install Maven 3. The simplest way to do this on Ubuntu is using apt-get:

sudo apt-get install maven

This command fetches and installs the latest Maven version available in the Ubuntu repositories. Once the installation completes, verify the installation by running: mvn -version. This displays the Maven version, home directory, Java version, and other relevant information, confirming successful installation. This streamlined approach makes Maven readily accessible for your projects.

Setting up Maven Environment Variables (Optional)

While not strictly necessary for basic usage, setting up environment variables for Maven can enhance its integration with your system. This involves configuring M2_HOME and updating the PATH variable.

First, determine your Maven installation path (usually /usr/share/maven). Then, add the following lines to your ~/.bashrc file:

  • export M2_HOME=/usr/share/maven
  • export PATH=$PATH:$M2_HOME/bin

Apply the changes by running source ~/.bashrc. These configurations enable easier access to Maven commands and improve compatibility with certain IDEs and build tools.

Testing Your Maven Installation

After installing Maven, verify its functionality by creating a simple project. Navigate to your desired project directory and run:

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

This command generates a basic Maven project structure. Then, navigate into the newly created project directory (my-app) and run: mvn package. This command compiles the project and creates a JAR file in the target directory, signifying a successful Maven installation and proper configuration.

Infographic Placeholder: Visual representation of the Maven installation process.

Maven’s dependency management simplifies project setup by automatically downloading and managing required libraries. For instance, if your project depends on a specific logging library, you simply declare it in your project’s pom.xml file, and Maven handles the rest. This eliminates manual downloads and ensures consistent library versions across your projects. Learn more about dependency management.

Frequently Asked Questions

Q: What is the difference between Maven and Gradle?
A: Both are build tools, but Gradle uses a Groovy-based DSL, offering more flexibility, while Maven uses XML for configuration and is generally considered more stable and mature.

Using apt-get for Maven installation provides a reliable and efficient method, leveraging Ubuntu’s package management system. This approach ensures easy updates and seamless integration with your Ubuntu environment. Whether you are a seasoned developer or just starting, a properly installed Maven setup significantly improves your build process. Explore further by creating more complex projects and leveraging Maven’s advanced features. For additional resources and detailed documentation, visit the official Apache Maven website (https://maven.apache.org/) and the Ubuntu documentation (https://ubuntu.com/server/docs). Consider exploring Baeldung’s Maven tutorials for in-depth guides and best practices. This structured approach not only streamlines the initial setup but also contributes to a more organized and efficient development workflow.

Question & Answer :

Try:
sudo apt-get install maven 

If it works for you ignore the rest of this post.

Intro

I started setting up my Ubuntu 12.10 on April 2013 and the normal sudo apt-get install maven was not working for maven 3 back then.

The manual installation in this post is useful if you like to dig in deeper to your ubuntu kernel in regards with apt-get and where it finds the list of applications that are available for installation on Ubuntu . It can also be potentially useful for more recent releases of Ubuntu like Ubuntu 15.04, etc. if you face the same problem as I did back then with Ubuntu 12.10.

Automatic Installation via apt-get:

Checkout the manual installation if your current ubuntu can not install maven via common ‘apt-get install maven’.

sudo apt-get update sudo apt-get install maven 

Make sure to remove maven 2 if your ubuntu is not fresh or if you were using maven 2 before:

sudo apt-get remove maven2 

Manual Installation via apt-get by adding maven 3 repository (Ubuntu 14.04 check out update 1):

This can be useful if your ubuntu apt-get repositories list is not up to date.

Maven 3 was required to set up the system and as it turns out most of the documents out there are referring to how to install Maven to Ubuntu version 12.04 or before. Best document I found was:

killertilapia’s blog

The whole process I came up with is as follows:

  1. sudo -H gedit /etc/apt/sources.list

  2. Add the following line the sources.list file:

    deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main

    deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main

  3. sudo apt-get update && sudo apt-get install maven3

  4. sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn

Caution 1: command “sudo apt-add-repository ppa:natecarlson/maven3” did not work on my Ubuntu and had to run sudo apt-add-repository -rm ppa:natecarlson/maven3 to get my apt-get to work again.

Caution 2: thanks to David, you need to remove your existing symbolic link to previous versions of maven before running step 4.

OS X Installation

I decided to add OS X installation in case you use multiple environments for your dev: See the source stackoverflow thread for more details.

Install Homebrew that is the equavalent of apt-get, then install Maven using:

brew install maven 

Update 1: Installation for Ubunutu 14.04

Haven’t tried this myself but I am confident this should work without security warnings:

sudo apt-get purge maven maven2 maven3 sudo apt-add-repository ppa:andrei-pozolotin/maven3 sudo apt-get update sudo apt-get install maven3 

Note: source here, many thanks and +1s to @rendybjunior, @Dominic_Bartl, and @FunThomas424242

Here’s an easier way:

sudo apt-get install maven 

More details are here.