How to install Maven on Ubuntu

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

1. Search Maven package

In a terminal, run apt-cache search maven, to get all the available Maven package.


$ apt-cache search maven
....
libxmlbeans-maven-plugin-java-doc - Documentation for Maven XMLBeans Plugin
maven - Java software project management and comprehension tool
maven-debian-helper - Helper tools for building Debian packages with Maven
maven2 - Java software project management and comprehension tool

The maven package always comes with latest Apache Maven.

2. Install it

Run command sudo apt-get install maven, to install the latest Apache Maven.


$ sudo apt-get install maven

It takes few minutes to download, patient.

3. Verification

Run command mvn -version to verify your installation.


$ mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_09, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-17-generic", arch: "amd64", family: "unix"

The Apache Maven is installed successfully.

Where is Maven installed?
The command apt-get install the Maven in /usr/share/maven.


$ls -ls /usr/share/maven
total 16
4 drwxr-xr-x 2 root root 4096 Dec  7 01:28 bin
4 drwxr-xr-x 2 root root 4096 Dec  7 01:28 boot
0 lrwxrwxrwx 1 root root   10 May 28  2012 conf -> /etc/maven
4 drwxr-xr-x 2 root root 4096 Dec  7 01:28 lib
4 drwxr-xr-x 2 root root 4096 Dec  7 01:28 man

The Maven configuration files are stored in /etc/maven


$ls -ls /etc/maven
total 16
 4 -rw-r--r-- 1 root root   184 Jan 21  2012 m2.conf
12 -rw-r--r-- 1 root root 10224 Jan 21  2012 settings.xml

About the Author

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

Comments

Leave a Reply

avatar
newest oldest most voted
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

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”

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]

cybertraqye
Guest
cybertraqye

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

Prateek Mathur
Guest
Prateek Mathur

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

AndreiCh
Guest
AndreiCh

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

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.

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 […]