Bobcares

How to install and configure Apache Maven on Ubuntu 18.04?

PDF Header PDF Footer

Install of Apache Maven from the default Ubuntu repository often result in installing an older version of Maven.

As a part of our Server Management Services, we help our Customers with software installations regularly.

Let us today discuss the steps to install Apache Maven on Ubuntu

How to Install Apache Maven on Ubuntu?

Apache Maven can be installed either using apt or from the official website. Let us look at each of these methods in detail.

Install Apache Maven via Apt

The default Ubuntu package repository includes a package for Maven, and we can install it easily with the apt command. Prior to the package install, it is a good idea to update the existing packages in the system.

root@ubuntu:~# apt update -y

After the update, we can install Maven with the command below:

root@ubuntu:~# apt install maven -y

Now, to verify the installation, run the following command to check the version of Maven on the system:

root@ubuntu:~# mvn -v
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-91-generic", arch: "amd64", family: "unix"

 

Install Apache Maven via Download

Often the version of Maven within the Ubuntu repository is not the latest one. To obtain the most up-to-date version of Maven, we can install it after downloading the installation file from the Apache Maven website.

This method includes the following tasks:

  • Install OpenJDK
  • Download Maven
  • Extract Maven and Symlink
  • Configure Environment Variables
  • Verify Maven Installation

To proceed with this method, we need to install OpenJDK as Maven 3.3+ requires JDK 1.7 or above.

To install java, initially, we need to update the packages as we did earlier. Once the packages are up to date, install the OpenJDK package by typing:

root@ubuntu:~# apt install default-jdk

Now, verify the installation by running the following command:

root@ubuntu:~# java -version
Download Maven

The second task in this method is to download Maven into the /tmp directory utilizing the following command:

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

Next, extract the newly downloaded Maven archive to the /opt directory:

root@ubuntu:~# tar xf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt

To make it more straightforward to upgrade in the future, create a symlink to the Maven installation directory:

root@ubuntu:~# ln -s /opt/apache-maven-3.6.3 /opt/maven
Configure Environment Variables

To configure environment variables, initially, we need to create a maven.sh file inside the /etc/profile.d/ directory:

root@ubuntu:~# vim /etc/profile.d/maven.sh

Now, copy the following configuration out and paste it into the maven.sh file:

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

Then, make the script executable with chmod:

root@ubuntu:~# chmod +x /etc/profile.d/maven.sh

Finally, to get these variables into play in the environment, run the source command on the file:

root@ubuntu:~# source /etc/profile.d/maven.sh
Verify Maven Installation

Finally to verify that Maven is installed properly, run the version command and check the output:

root@ubuntu:~# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-91-generic", arch: "amd64", family: "unix"

 

[Need any further assistance in installing Apache Maven on Ubuntu? – We’re available 24*7]

Conclusion

In short, Apache Maven is a popular build management tool for Java projects. Today we saw two different method of how our Support Engineers install Apache Maven on Ubuntu.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments

Submit a Comment

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

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF