• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to install Apache Maven on Ubuntu

1369

How to install Apache Maven on Ubuntu

Apache Maven is free and open source Project Management tool which can be used for Java projects. It provides a framework to automate the project’ s build infrastructure. This tutorial explains the installation of Apache Maven on Ubuntu.

Installation procedure

Before installing Apache Maven, update your system repositories by running the following command.

root@linuxhelp1:~# apt-get update
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists... Done

The Apache Maven needs the Java Development Kit (JDK) to be installed first . Now use the below command to add the repository to install Java 8

root@linuxhelp1:~# add-apt-repository ppa:webupd8team/java
 Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA.
More info (and Ubuntu installation instructions):
- for Oracle Java 7: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
- for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html
Debian installation instructions:
- Oracle Java 7: http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html
- Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
Oracle Java 9 (for both Ubuntu and Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html
For JDK9, the PPA uses standard builds from: https://jdk9.java.net/download/ (and not the Jigsaw builds!).
Important!!! For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps. More information and installation instructions (Ubuntu / Linux Mint / Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html
 More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmplii8t4x4/secring.gpg'  created
gpg: keyring `/tmp/tmplii8t4x4/pubring.gpg'  created
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmplii8t4x4/trustdb.gpg: trustdb created
gpg: key EEA14886: public key " Launchpad VLC"  imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

Once the new repository is added use the apt-get update command to update the recently made changes to the system.

root@linuxhelp1:~# apt-get update
Get:1 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease [17.6 kB]
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial InRelease                    
Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease                                        
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease     
Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease   
Get:6 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main amd64 Packages [2,864 B]
Get:7 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main i386 Packages [2,864 B]
Get:8 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main Translation-en [1,260 B]
Fetched 24.6 kB in 1s (24.0 kB/s)
Reading package lists... Done

Now install Oracle Java installer version 8 and press y to continue.

root@linuxhelp1:~# apt-get install oracle-java8-installer -y
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  gsfonts-x11 java-common oracle-java8-set-default
Suggested packages:
  binfmt-support visualvm ttf-baekmuk | ttf-unfonts | ttf-unfonts-core ttf-kochi-gothic | ttf-sazanami-gothic ttf-kochi-mincho | ttf-sazanami-mincho ttf-arphic-uming
The following NEW packages will be installed:
  gsfonts-x11 java-common oracle-java8-installer oracle-java8-set-default
0 upgraded, 4 newly installed, 0 to remove and 469 not upgraded.
Need to get 54.6 kB of archives.
After this operation, 272 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main amd64 oracle-java8-installer all 8u121-1~webupd8~2 [32.9 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 java-common all 0.56ubuntu2 [7,742 B]
.
.
.
Selecting previously unselected package oracle-java8-set-default.
(Reading database ... 176757 files and directories currently installed.)
Preparing to unpack .../oracle-java8-set-default_8u121-1~webupd8~2_all.deb ...
Unpacking oracle-java8-set-default (8u121-1~webupd8~2) ...
Selecting previously unselected package gsfonts-x11.
Preparing to unpack .../gsfonts-x11_0.24_all.deb ...
Unpacking gsfonts-x11 (0.24) ...
Processing triggers for fontconfig (2.11.94-0ubuntu1) ...
Setting up oracle-java8-set-default (8u121-1~webupd8~2) ...
Setting up gsfonts-x11 (0.24) ...

After installing Java, verify it’ s version by running the following command.

root@linuxhelp1:~# java -version
java version " 1.8.0_121" 
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Now to install the apache maven, move to /opt/ directory for the installation and from there download package for Apache Maven.

root@linuxhelp1:~# cd /opt/
root@linuxhelp1:/opt# wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
--2017-04-07 15:00:24--  http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
Resolving www-eu.apache.org (www-eu.apache.org)... 88.198.26.2, 2a01:4f8:130:2192::2
Connecting to www-eu.apache.org (www-eu.apache.org)|88.198.26.2|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8491533 (8.1M) [application/x-gzip]
Saving to: ‘ apache-maven-3.3.9-bin.tar.gz’ 
apache-maven-3.3.9-bin.tar.gz                 100%[===============================================================================================> ]   8.10M  70.7KB/s    in 73s    
2017-04-07 15:01:38 (113 KB/s) - ‘ apache-maven-3.3.9-bin.tar.gz’  saved [8491533/8491533]

Now extract the Maven package using tar command.

root@linuxhelp1:/opt# tar -xvzf apache-maven-3.3.9-bin.tar.gz
apache-maven-3.3.9/boot/plexus-classworlds-2.5.2.jar
apache-maven-3.3.9/lib/maven-embedder-3.3.9.jar
apache-maven-3.3.9/lib/maven-settings-3.3.9.jar
apache-maven-3.3.9/lib/plexus-utils-3.0.22.jar
apache-maven-3.3.9/lib/maven-core-3.3.9.jar
apache-maven-3.3.9/lib/maven-model-3.3.9.jar
apache-maven-3.3.9/lib/commons-lang3-3.4.jar
apache-maven-3.3.9/lib/maven-settings-builder-3.3.9.jar
apache-maven-3.3.9/lib/maven-builder-support-3.3.9.jar
apache-maven-3.3.9/lib/plexus-interpolation-1.21.jar
apache-maven-3.3.9/lib/plexus-component-annotations-1.6.jar
.
.
.
apache-maven-3.3.9/bin/mvnDebug
apache-maven-3.3.9/bin/mvnyjp
apache-maven-3.3.9/conf/
apache-maven-3.3.9/conf/logging/
apache-maven-3.3.9/conf/logging/simplelogger.properties
apache-maven-3.3.9/conf/settings.xml
apache-maven-3.3.9/conf/toolchains.xml
apache-maven-3.3.9/lib/ext/
apache-maven-3.3.9/lib/ext/README.txt

The package has been extracted succesfully. Now rename the newly extracted directory.

root@linuxhelp1:/opt# mv apache-maven-3.3.9 maven

Next we need to setup Environment Variables for Apache Maven. In order to do that create new script file under /etc/profile.d/ directory.

root@linuxhelp1:/opt# vim /etc/profile.d/mavenenv.sh

Create the following entries in mavenenv.sh file. Save and exit from the file.

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

After creating environment variables, we need to load the environment variables by executing the following command.

root@linuxhelp1:/opt# source /etc/profile.d/mavenenv.sh

Now verify the version of apache maven.

root@linuxhelp1:/opt# mvn -V
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5  2015-11-10T22:11:47+05:30)
Maven home: /opt/maven
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: " linux" , version: " 4.4.0-21-generic" , arch: " amd64" , family: " unix" 

Wasn' t that an easy installation process? Apache Maven is based on the project object model (POM).

Tags:
nicholas
Author: 

Comments ( 2 )

parthiban
Thanks for your Feedback and keep in touch for further tutorials
ayushgarg
AWESOME ARTICLE. Thank you so much.
Add a comment

Frequently asked questions ( 5 )

Q

Where you have downloaded latest link of Apache Maven?

A

To download the latest releases of Apache Maven see this link "http://www-eu.apache.org/dist/maven/"

Q

What for you have created /etc/profile.d/mavenenv.sh?

A

To setup Environment Variables for Apache Maven.

Q

What is the essential purpose of using this ?

A

Maven is a build automation tool used primarily for Java projects

Q

I can't seem to get JUnit to show up in the classpath. What gives in Apache Maven?

A

Must have some unit tests for your project, otherwise JUnit is ignored.

Q

What is Apache Maven?

A

Apache Maven is free and open source Project Management tool which can be used for Java projects.

Related Tutorials in How to install Apache Maven on Ubuntu

Related Tutorials in How to install Apache Maven on Ubuntu

How to install Meld tool in Ubuntu
How to install Meld tool in Ubuntu
Feb 25, 2017
How to install Dconf-Editor on Ubuntu 18.04
How to install Dconf-Editor on Ubuntu 18.04
Jul 14, 2018
How to install and update OpenSSL on Ubuntu 16.04
How to install and update OpenSSL on Ubuntu 16.04
Mar 9, 2017
How to install GLib 2.0 on Ubuntu 17.04
How to install GLib 2.0 on Ubuntu 17.04
May 22, 2017
How to Install Android Emulator on Ubuntu 20.4.1
How to Install Android Emulator on Ubuntu 20.4.1
Jul 13, 2021
How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How To Install AnyDesk on Ubuntu 16.04
How To Install AnyDesk on Ubuntu 16.04
Apr 4, 2018
How to install Genymotion 2.12.1 on Ubuntu 18.04
How to install Genymotion 2.12.1 on Ubuntu 18.04
Jul 9, 2018

Related Forums in How to install Apache Maven on Ubuntu

Related Forums in How to install Apache Maven on Ubuntu

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
Ubuntu
matthew class=
Failed to enable unit: Refusing to operate on linked unit file sshd.service
Apr 15, 2019
Ubuntu
mason class=
Passwd: You may not view or modify password information for root On Ubuntu 19.04
May 27, 2019
Ubuntu
isaac class=
/etc/apt/sources.list Permission denied
May 18, 2017
Ubuntu
yousuf class=
lsb_release command not working : Debian
Jan 18, 2018
ifconfig command
jackbrookes class=
what is the location of the ifconfig program on your machine?
Jan 4, 2018
Ubuntu
mason class=
"E: Package 'php-mcrypt' has no installation candidate" error on Ubuntu 20.4.1
Mar 15, 2021
NFS
luke class=
clnt_create: RPC: Program not registered
Apr 25, 2017

Related News in How to install Apache Maven on Ubuntu

Related News in How to install Apache Maven on Ubuntu

How To Install Mixxx on Ubuntu 16.04
How To Install Mixxx on Ubuntu 16.04
Oct 11, 2017
Ubuntu 17.04 released with greater expectations
Ubuntu 17.04 released with greater expectations
Apr 15, 2017
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Mar 1, 2017
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Sep 2, 2017
Ubuntu Unity is no more: One Linux dream has been axed
Ubuntu Unity is no more: One Linux dream has been axed
Apr 7, 2017
What’s next for Ubuntu Linux Desktop?
What’s next for Ubuntu Linux Desktop?
Apr 11, 2017
Say Hi to Ubuntu's new mascot
Say Hi to Ubuntu's new mascot
Mar 22, 2019
Attackers take advantage of Apache Struts vulnerabilities
Attackers take advantage of Apache Struts vulnerabilities
Mar 17, 2017
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.