How to install Maven on Ubuntu
In this tutorial, we will show you how to install Apache Maven on Ubuntu.
Tested with
- Maven 3.5.2
- Ubuntu 18.04
Note
Before the Maven installation, make sure JDK is installed and JAVA_HOME is configured.
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
Thanks. As always your tutorials are just to the point.
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”
i see what happen, you need to set JAVA_HOME variable :))
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
you must export your java version in path
see ubuntu documentation
https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
Nice information, but we may have to run mvn once to generate the ~/.m2 folder, as it is not generated just by installing maven.
xiexie
Wonderful! simple command. helped a lot
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]
Can you please explain how can I install maven 3.1.0 on Ubuntu 14.04 LTS?
very easy :)! I have tried from other sites to download maven but this is the easiest way :)! Thank you
Works in 12.04!
E: Unable to locate package maven , I got this. I am trying to install in ubuntu 13.10
try this command
whereis maven
Simple and clear tutorial, Thanks
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)
Good day sir,
If after i deployed my project. will maven automatically download the updated dependencies.
thank u.
Outstanding tutorials, has helped me a whole lot, keep it up.
@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/
Very straightforward and thorough guideline.
Appreciate!
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:~$
Too bad there’s no maven3 option apparently?
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.
Another installation procedure for maven with Nexus configuration
http://www.java-tutorial.ch/ubuntu/maven-installation-and-configuration-for-ubuntu
Consider this as a better alternative
http://ubuntu-answers.blogspot.com/2010/12/install-maven-on-ubuntu-linux.html
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.
You are my libraries … \o/
that tuto is not compatible with linux Mint 🙂
but okay with ubuntu