Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install Apache Maven on Ubuntu 20.04 - DesignLinux

designlinux 0 Comments

Apache Maven is an open-source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM), which is essentially an XML file containing information about the project, configuration details, the project’s dependencies, and more.

In this tutorial, we will show you two different ways to install Apache Maven on Ubuntu 20.04.

The official Ubuntu repositories contain Maven packages that can be installed with the apt package manager. This is the easiest way to install Maven on Ubuntu. However, the version included in the repositories may lag behind the latest version of Maven.

To install the latest version of Maven, follow the instructions provided in the second part of this article that shows how to download the binary distribution archive from their official website.

Choose the installation method that is most appropriate for your setup and environment.

Prerequisites #

The instructions assume that you are logged in as root or user with sudo privileges.

Installing Apache Maven on Ubuntu 20.04 with apt #

Installing Maven on Ubuntu using apt is a simple, straightforward process.

Update the package index and install Maven by entering the following commands:

sudo apt updatesudo apt install maven

To verify the installation, run mvn -version:

mvn -version

The output should look something like this:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-26-generic", arch: "amd64", family: "unix"

That’s it. Maven is now installed on your system, and you can start using it.

Installing the Latest Release of Apache Maven #

In this section, we’ll provide a step by step instructions about how to download and install the latest Apache Maven version on Ubuntu 20.04.

1. Install OpenJDK #

Maven 3.3+ requires JDK 1.7 or above to be installed.

Install OpenJDK 11, by typing:

sudo apt updatesudo apt install default-jdk

Verify the installation by running the following command:

java -version

The output should look something like this:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

2. Downloading Apache Maven #

At the time of writing this article, the latest version of Apache Maven is 3.6.3. Before continuing with the next step, visit the Maven download page to see if a newer version is available.

Download the Apache Maven in the /tmp directory:

wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

Once the download is completed, extract the archive in the /opt directory:

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

To have more control over Maven versions and updates, we will create a symbolic link maven that will point to the Maven installation directory:

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

When a new version is released, you can upgrade your Maven installation, by unpacking the newer version and change the symlink to point to it.

3. Setup environment variables #

Next, we’ll need to set up the environment variables. To do so, open your text editor and create a new file named mavenenv.sh in the /etc/profile.d/ directory.

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

Paste the following code:

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

Save and close the file. This script will be sourced at shell startup.

Make the script executable with chmod:

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

Finally, load the environment variables using the source command:

source /etc/profile.d/maven.sh

4. Verify the installation #

To verify that Maven is installed, use the mvn -version command which will print the Maven version:

mvn -version

You should see something like the following:

Maven home: /opt/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-26-generic", arch: "amd64", family: "unix"

That’s it. The latest version of Maven is now installed on your Ubuntu system.

Conclusion #

We have shown you how to install Apache Maven on Ubuntu 20.04. You should now visit the official Apache Maven Documentation page and learn how to get started with Maven.

If you hit a problem or have feedback, leave a comment below.

java maven ubuntu

Related

Tags: java, maven, ubuntu

How to Install Apache Maven on Ubuntu 20.04

Prev Post

How to Install TeamViewer on Debian 10

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 2
  • 82
  • 605,832

DesignLinux.com © All rights reserved

Go to mobile version