Main Tutorials

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 Author

author image
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

Subscribe
Notify of
28 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
AndreiCh
8 years ago

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

GosuSfaccim
6 years ago

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
5 years ago
Reply to  GosuSfaccim

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

Taemina
8 years ago

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
8 years ago
Reply to  Taemina

you must export your java version in path
see ubuntu documentation

Nick Halden
10 years ago

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
5 years ago

Wonderful! simple command. helped a lot

jjmkay
8 years ago

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
8 years ago

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

Venkata Sai
10 years ago

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

Venkata Sai
10 years ago
Reply to  Venkata Sai

Works in 12.04!

bkira
10 years ago

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

Venkata Sai
10 years ago
Reply to  bkira

try this command
whereis maven

Dhanushanth
10 years ago

Simple and clear tutorial, Thanks

mje
10 years ago

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
11 years ago

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

thank u.

Rikard
11 years ago

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

elvis1
11 years ago

@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
11 years ago

Very straightforward and thorough guideline.
Appreciate!

haris
11 years ago

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
11 years ago

Too bad there’s no maven3 option apparently?

SmugAdmin
12 years ago

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
12 years ago

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

anton
13 years ago
anton
13 years ago

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.

Sitthykun
13 years ago

You are my libraries … \o/

cybertraqye
8 years ago

that tuto is not compatible with linux Mint 🙂
but okay with ubuntu