How to install Maven 3 on Ubuntu by using apt-get?
Get Maven rocking on your Ubuntu with just two commands:
Check the installation with mvn -version
.
Installing on older Ubuntu versions
Previous Ubuntu versions (17.04 and earlier) require a little more love. Before Maven can be installed, a Personal Package Archive (PPA) must be added.
PPA: How to add it
- Install the
software-properties-common
package, because some common software properties can be uncommonly useful:
- Add the Maven PPA (be sure to use something reputable, or Maven's own PPA if available):
- Update the package list, because freshness matters:
Maven: Let's install
With the PPA nicely tucked in, command the install:
After the magic
- Prove that Maven answered your summon with
mvn -version
. - If the PPA was merely for the Maven installation, consider letting it go for a cleaner system.
When Maven family reunions go wrong
If your system still houses older Maven residents, you'll want to evict them to make room for Maven 3:
After the clean-up, feel free to introduce Maven 3 to your system.
Manual installation for the adventurous
Fancy a specific Maven version or dealing with a repository rejection? Manual installation is your adventure.
- Hunt down the Maven binaries from the official Maven forest.
- Set up camp by extracting the archive to a directory of your choice.
- Edit your
~/.bashrc
or~/.profile
map, leading to thebin
directory of the new camp. - Link Maven’s
JAVA_HOME
to your JDK installation: addexport JAVA_HOME=/path/to/your/jdk
in your~/.bashrc
or~/.profile
. Don't forget to replace the/path/to/your/jdk
with the real path. - Refresh your system with the new modifications using
source ~/.bashrc
orsource ~/.profile
.
Making it work (tips and gotchas)
Dependencies covered?
Ensure all dependencies are installed, particularly JDK (Java Development Kit).
Paths and environment
The bin
directory of Maven should be in the system's $PATH variable. They must see eye-to-eye for Maven to work smoothly.
Check, double check
Verify Maven installation with mvn -version
, and ensure Java is in sync with it.
Repositories: Yes, they need cleaning too
PPAs aren't self-cleaning. After Maven installation, decide whether to keep or discard the PPA.
Was this article helpful?