How to install Maven on Ubuntu 16.04
In this tutorial, we will show you how to install Apache Maven 3 on Ubuntu 16.04 VPS. Apache Maven is a free and open source project management software written in Java. Based on the concept of the Project Model Object (POM), Maven can manage all the projects it builds. With Maven, you can easily store documents, generate reports and documentation from a central piece of information. Installing Maven on Ubuntu 16.04 is a fairly simple task and shouldn’t take more than 10 minutes.
Some of the main Maven 3 features are listed below:
- Easy project setup
- Plugin extension points
- Maven wrapper
- Consistent use of all projects
- Builder model
- Automatic versioning barent
- Dependency management
- Parallel assemblies
- and much more ..
1. Login with SSH
First of all, login to your Ubuntu 16.04 VPS via SSH as superuser
ssh [email protected]_Address -p Port_number
2. Updating OS packages
Update all installed packages to the latest version
apt-get update && apt-get upgrage
3. Check your Maven version
Installing Apache Maven is a very simple process. It is available in the official Ubuntu 16.04 repository. You can check the exact version by running the following command
apt-cache show maven | grep Version Version: 3.3.9-3
4. Install Maven from the official repository
Version 3.3.9 is currently installed. Please note that the latest available Apache Maven version is currently 3.5.2 and this is the recommended option for all users.
To proceed with the installation, run the following command
apt-get -y install maven
This will install the latest version of Maven 3 available in the repository among all Maven dependencies, including Java.
After the installation is complete, you can check if Maven has been successfully installed on your Ubuntu 16.04 server by using the following command
mvn --version
The result should be similar to
Apache Maven 3.3.9 Maven home: /usr/share/maven Java version: 1.8.0_151, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre Default locale: en_US, platform encoding: ANSI_X3.4-1968 OS name: "linux", version: "2.6.32-042stab127.2", arch: "amd64", family: "unix"
5. Installation Guide
As we mentioned, 3.3.9 is not the latest version of Maven. If you want to install the latest version, you can download it from the Maven official website. First of all, we need to install Java on the server. It is not available in the official Ubuntu 16.04 repository, so we will add the PPA repository maintained by the Webupd8 team
apt-get install software-properties-common apt-add-repository ppa:webupd8team/java apt-get update
6. Installing Java
Then install Java 8 using the following command
apt-get install oracle-java8-installer
To check if the installation is correct, run
java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
7. Download the latest version of Maven
Download the latest stable version of Maven
wget http://ftp.wayne.edu/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.zip
After downloading, unzip the archive
unzip apache-maven-3.5.2-bin.zip
8. Configuring Maven
Rename the created directory to something simpler
mv apache-maven-3.5.2 maven
Set the required environment variables, create a new file with the following content
nano /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/java-8-oracle export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
Make sure all paths are correct.
Run the following command to load environment variables
source /etc/profile.d/maven.sh
9. Verifying Maven Installation
And finally make sure Maven is installed correctly
mvn -version