How to install Maven on Ubuntu

In this tutorial, we will show you how to install Apache Maven on Ubuntu.

Tested with

  1. Maven 3.5.2
  2. Ubuntu 18.04
Note
Before the Maven installation, make sure JDK is installed and JAVA_HOME is configured.

1. Search Maven

Review the Maven package version in the local repository.


$ sudo apt policy maven

maven:
  Installed: (none)
  Candidate: 3.5.2-2
  Version table:
     3.5.2-2 500
        500 http://my.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        500 http://my.archive.ubuntu.com/ubuntu bionic/universe i386 Packages

It is Maven 3.5.2.

2. Install Maven

Install the Maven via apt command.


$ sudo apt install maven

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libaopalliance-java libapache-pom-java libatinject-
  
//...

Setting up libsisu-inject-java (0.3.2-2) ...
Setting up libsisu-plexus-java (0.3.3-3) ...
Setting up libmaven3-core-java (3.5.2-2) ...
Setting up maven (3.5.2-2) ...
update-alternatives: using /usr/share/maven/bin/mvn to provide /usr/bin/mvn (mvn) in auto mode

3. Verification

Apache Maven 3.5.2 is installed successfully.


$ mvn -version

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 11.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-38-generic", arch: "amd64", family: "unix"

4. Where is Maven?

The apt command installed Maven in the following location :


$ ls -lsa /usr/share/maven
total 32
 4 drwxr-xr-x   6 root root  4096 Nov   9 17:34 .
12 drwxr-xr-x 227 root root 12288 Nov   9 17:34 ..
 4 drwxr-xr-x   2 root root  4096 Nov   9 17:34 bin
 4 drwxr-xr-x   2 root root  4096 Nov   9 17:34 boot
 0 lrwxrwxrwx   1 root root    10 Feb  24  2018 conf -> /etc/maven
 4 drwxr-xr-x   2 root root  4096 Nov   9 17:34 lib
 4 drwxr-xr-x   2 root root  4096 Nov   9 17:34 man

$ ls -lsa /etc/maven
total 40
 4 drwxr-xr-x   3 root root  4096 Nov   9 17:34 .
12 drwxr-xr-x 127 root root 12288 Nov   9 17:34 ..
 4 drwxr-xr-x   2 root root  4096 Nov   9 17:34 logging
 4 -rw-r--r--   1 root root   220 Okt  18  2017 m2.conf
12 -rw-r--r--   1 root root 10211 Okt  18  2017 settings.xml
 4 -rw-r--r--   1 root root  3645 Okt  18  2017 toolchains.xml

References

  1. How to install Java JDK on Ubuntu

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
30 Comment threads
5 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
23 Comment authors
Sai Teja MakaniHandsomeGosuSfaccimjjmkaycybertraque Recent comment authors
newest oldest most voted
AndreiCh
Guest
AndreiCh

Thanks. As always your tutorials are just to the point.

GosuSfaccim
Guest
GosuSfaccim

i have a Warning:

mvn -version
Warning: JAVA_HOME environment variable is not set.
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: it_IT, platform encoding: UTF-8
OS name: “linux”, version: “4.4.0-81-generic”, arch: “amd64”, family: “unix”

Handsome
Guest
Handsome

i see what happen, you need to set JAVA_HOME variable :))

Taemina
Guest
Taemina

hello :)

when I run ‘mvn -version’, the result is: ‘Error: JAVA_HOME is not defined correctly. We cannot execute /usr/bin/java/bin/java’

I’ve installed java and add JAVA_PATH to /etc/environment. Can someone help me? Thanks

cybertraque
Guest
cybertraque

you must export your java version in path
see ubuntu documentation

Nick Halden
Guest
Nick Halden

Nice information, but we may have to run mvn once to generate the ~/.m2 folder, as it is not generated just by installing maven.

Sai Teja Makani
Guest
Sai Teja Makani

Wonderful! simple command. helped a lot

jjmkay
Guest
jjmkay

should we be concerned with unauthenticated software packages? 0 upgraded, 83 newly installed, 0 to remove and 31 not upgraded.
Need to get 40.2 MB of archives.
After this operation, 66.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
libbatik-java libcommons-httpclient-java libjetty-java libjackrabbit-java
Install these packages without verification? [y/N]

Prateek Mathur
Guest
Prateek Mathur

Can you please explain how can I install maven 3.1.0 on Ubuntu 14.04 LTS?

Venkata Sai
Guest
Venkata Sai

very easy :)! I have tried from other sites to download maven but this is the easiest way :)! Thank you

Venkata Sai
Guest
Venkata Sai

Works in 12.04!

bkira
Guest
bkira

E: Unable to locate package maven , I got this. I am trying to install in ubuntu 13.10

Venkata Sai
Guest
Venkata Sai

try this command
whereis maven

trackback
???Mahout??——Canopy Clustering | seeksky

[…]       2???mvn?????????sudo apt-get install maven2?????????http://www.mkyong.com/maven/how-to-install-maven-in-ubuntu/? […]

Dhanushanth
Guest
Dhanushanth

Simple and clear tutorial, Thanks

trackback
???Mahout??——Canopy Clustering | seeksky

[…]       2???mvn?????????sudo apt-get install maven2?????????http://www.mkyong.com/maven/how-to-install-maven-in-ubuntu/? […]

mje
Guest
mje

Perfect tutorial, clear and straightforward. Thx a lot !
(PS : you’ll be in fact downloading maven 3 from the maven repo which is great imo, so don’t worry about getting an old version this way, it works perfectly :) There’s also a maven2 repo for those who want the previous version)

JProgrammer
Guest
JProgrammer

Good day sir,
If after i deployed my project. will maven automatically download the updated dependencies.

thank u.

Rikard
Guest
Rikard

Outstanding tutorials, has helped me a whole lot, keep it up.

elvis1
Guest
elvis1

@haris: check your repos ;).

You should do this :

1)sudo apt-get update
2) sudo apt-get install nano
3)Make a backup of your repo list ( cp /etc/apt/sources.list /etc/apt/sources.list.bak)
4)a)sudo nano /etc/apt/sources.list
b) Insert whatever this spits out ( take into account to enter your corresponding Debian based version) :
http://repogen.simplylinux.ch/

elvis1
Guest
elvis1

Very straightforward and thorough guideline.
Appreciate!

haris
Guest
haris

hi, i m getting following problem , please somebody help me…

haris@haris-Aspire-4752:~$ sudo apt-get install maven2
[sudo] password for haris:
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package maven2
haris@haris-Aspire-4752:~$

roger
Guest
roger

Too bad there’s no maven3 option apparently?

SmugAdmin
Guest
SmugAdmin

I have a Dak Tech computer with Intel Pentium 4,Ubuntu Studio 11.04,and Linux For Creative Humans.I forgot my user account user name and password.I need to know how I can bypass it or get new name and password so I can use my computer.

David
Guest
David

Another installation procedure for maven with Nexus configuration
http://www.java-tutorial.ch/ubuntu/maven-installation-and-configuration-for-ubuntu

trackback
vm-ubuntu-build???? | devchina
anton
Guest
anton
anton
Guest
anton

This is far from being the best way. 90Mb of archives to download??
maven is a java application, which will run on any platform. The dowload size of the binary from apache site is ~3Mb. The only thing is to unpack add the mvn script to your path.

trackback
Install Apache Maven in Ubuntu | Andrew McAlorum

[…] Mkyong.com. Posted on December 15, 2010 by admin. This entry was posted in From the Command Line, […]

Sitthykun
Guest
Sitthykun

You are my libraries … \o/

trackback
PRSoluções » Blog Arquivo » Criar projeto web (WTP) com maven habilitando importação via Eclipse
trackback
Maven Tutorials | Tutorials

[…] Install Maven in *nix environment (Ubuntu) Article about how to install Ubuntu. […]

trackback
How to integrate between Apache Archiva and Maven | Maven

[…] – How to install Maven in Windows – How to install Maven in Ubuntu […]

cybertraqye
Guest
cybertraqye

that tuto is not compatible with linux Mint :)
but okay with ubuntu