How to install Apache Maven on Ubuntu 20.04

This article was first published in: https://www.itcoder.tech/posts/how-to-install-apache-maven-on-ubuntu-20-04/

Article Directory

Apache Maven is an open source project management tool, mainly used for Java projects. Maven uses a project object model (POM), which is a basic XML information that contains project information, configuration details, project dependencies, and so on.

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

The official Ubuntu software source contains Maven packages, which can be installed through the apt package management tool. This is the easiest way to install Maven on Ubuntu. In any case, the Maven version number in the software source will lag behind the latest Maven version number.

To install the latest version of Maven, follow the instructions provided in the second part of the article and download the binary compressed package from the official Maven website.

Choose the installation method that best suits your installation configuration and environment.

1. Prerequisites##

These instructions assume that you have logged into the system as root or another sudo user.

2. Use apt to install Apache Maven on Ubuntu 20.04

Installing Maven on Ubuntu using apt is very simple and straightforward.

Upgrade the package index and enter the following command to install Maven:

sudo apt update
sudo apt install maven

To verify that the installation was successful, run mvn -version:

mvn -version

The output looks 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 are already using it.

Three, install the latest version of Apache Maven

In this chapter, we will provide step-by-step instructions on downloading and installing the latest version of Apache Maven on Ubuntu 20.04.

  1. Install OpenJDK

Maven 3.3+ install JDK 1.7 or above.

Enter the following command to install OpenJDK 11:

sudo apt update
sudo apt install default-jdk

Run the following command to verify the installation process:

java -version

The output looks 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)
  1. Download Apache Maven

At the time of writing, the latest version of Apache Maven is 3.6.3. After continuing to the next step, browse Maven download page to see if there is a newer version available.

Download Apache Maven to 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 complete, unzip the compressed package to the /opt directory:

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

To have better control over Maven versions and updates, we will create a symbolic link to 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 in the following way: unzip the new version and modify the symbolic link to point to it.

  1. Set environment variables

Next, we will set environment variables. To do this, open your text editor and create a new file in the /etc/profile.d/ directory and name it mavenenv.sh.

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

Paste the code below:

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. The script will take effect when the shell is started.

To make the script executable, use chmod:

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

Finally, use the source command to reload the environment variables.

source /etc/profile.d/maven.sh
  1. Verify the installation process

To verify whether Maven is installed successfully, use the mvn -version command, it will print the Maven version:

mvn -version

You should see a message similar to 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 has been successfully installed on your Ubuntu system.

Four, summary##

We have shown you how to install Apache Maven on Ubuntu 20.04. You can now browse the official Apache Maven Documentation Page and learn how to get started with Maven.




If you have any questions, please contact us in the following ways:

WeChat:

WeChat group: add the above WeChat, remark the WeChat group

QQ: 3217680847

QQ Group: 82695646

Original: https://linuxize.com/post/how-to-install-apache-maven-on-ubuntu-20-04/

 Copyright notice: This work uses Creative Commons attribution-Share 4 in the same way.0 International license agreement for licensing.

related suggestion#

Recommended Posts

How to install Apache Maven on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Apache Maven on CentOS 8
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install Apache on CentOS 8
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install Apache Kafka on CentOS 7
How to install MySQL on Ubuntu 18.04 (linux)