Home / How To / How to install Apache Maven on Ubuntu 20.04

How to install Apache Maven on Ubuntu 20.04



Apache Maven is a free and open source project management tool primarily for Java projects. It is based on POM and is also used to build and manage projects written in C #, Ruby, Scala and others. It comes with built-in lens commands that can be used to manage packages and code composition.

In this tutorial we will show you how to install the Apache Maven project management tool on Ubuntu 20.04.

Conditions

  • A server running Ubuntu 20.04.
  • A root password is configured on the server.

Install Java

Apache Maven is based on Java. So Java must be installed on your server. You can install Java with the following command:

apt-get install default-jdk -y

Once Java has been installed, you can verify the installed version of Java with the following command:

java --version

You should get the following output:

openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

Install Apache Maven from the Ubuntu Repository

By default, Apache Maven is available in the standard Ubuntu 20.04 repository. You can install it with the following command:

apt-get install maven -y

When the installation is complete, you can verify the Apache Maven version with the following command:

mvn -version

You should get the following output:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.8, 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-29-generic", arch: "amd64", family: "unix"

Install Apache Maven from source

You can also install Apache Maven from source. First, download the latest version of Apache Maven with the following command:

wget https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

When the download is complete, extract the downloaded file with the following command:

tar -xvf apache-maven-3.6.3-bin.tar.gz

Then move the extracted directory to / opt with the following command:

mv apache-maven-3.6.3 /opt/maven

Then create a new maven.sh and set the Maven environment variables.

nano /etc/profile.d/maven.sh

Add the following lines:

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, then grant driving permission and activate the environment variables with the following command:

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

Then check the Maven version with the following command:

mvn -version

You should get the following output:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 11.0.8, 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-29-generic", arch: "amd64", family: "unix"

Conclusion

In the guide above, you learned how to install Apache Maven using different methods on Ubuntu 20.04. I hope you can now easily install your version of Maven in your system.

Hitesh Jethva

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include in-depth knowledge of Redhat / Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, security etc.


Source link