Apache Maven is a free and open source project management tool used for Java projects. You can easily manage a project’s build, reporting, and documentation using Apache Maven. In this post you will learn how to install and configure Apache maven on ubuntu 16.04/18.04 or any ubuntu./Debian based latest releases.
There are two ways to install Apache Maven on Ubuntu 16.04/18.04 LTS. Here we will explain both the methods .
1.Install Apache Maven from Ubuntu Repositories using apt
-This is the easiest way to install Maven on Ubuntu. However the version included in the repositories may not be the latest
2.Install Maven by downloading from official website
-In this method we can install the latest version of maven release by downloading from the official website https://maven.apache.org/download.cgi
Before we begin:
- A user with sudo privileges
- Java 1.7 or above
Java is the primary requirement of installing Apache Maven on Linux . So first you need to install Java on your system. Also make sure it is JDK version not JRE.
If you have only JRE installed on your system , maven will not be installed .To know the difference between JDK & JRE please check this link https://stackoverflow.com/questions/1906445/what-is-the-difference-between-jdk-and-jre
If java is not installed please follow our guide How to install and configure java on ubuntu 16.04/18.04 LTS-PART 1 .After that only continue this tutorial
Before maven installation check the version of java installed using below command :
java -version
It shows that oracle jdk 1.8 java is present .
Install Apache Maven from Ubuntu Repositories using apt
Installing Maven on Ubuntu using apt
is a simple process.
Step 1.update the package
Make sure that you have the latest stable version of Ubuntu 16.04.
sudo apt update
2.Install maven
sudo apt install maven
3.Verify the installation
mvn -version
Will get output look like below :
That’s it. Maven is now installed on your system, and you can start using it
2.Install Maven by downloading from official website
Step 1.Download maven and extract
You can download the latest stable version of Apache Maven from its official website https://maven.apache.org/download.cgi
Here we are downloading maven version3.6.2. You can select the latest versions also from the https://maven.apache.org/download.cgi
Now we can start by downloading the Apache Maven in the /
opt directory using the following wget
command:
cd /opt
wget http://www-eu.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
Once the download is completed, extract the archive in the /opt
directory using the below command
sudo tar xzf apache-maven-3.6.2-bin.tar.gz
2.Setup environment variables
Now set the environments variables by creating a new file named maven.sh under /etc/profile.d/ folder .By doing so our system will understand the maven path
sudo nano /etc/profile.d/maven.sh
Now add the below contents to this file .Then save and close the file
export JAVA_HOME=/home/rajesh/Documents/softwares/jdk1.8.0-231 export M2_HOME=/opt/apache-maven-3.6.2 export MAVEN_HOME=/opt/apache-maven-3.6.2 export PATH=${M2_HOME}/bin:${PATH}
Here Kindly note the JAVA_HOME and MAVEN_HOME .You can replace as per the location of your files
Now load the environment variables in current shell using following command.
source /etc/profile.d/maven.sh
step3. Verify the installation
Now it is the time to check our installation .For that use the following command to check the version of Maven
mvn -version
That’s it. The latest version of Maven is now installed on your Ubuntu system
You can now visit the official Apache Maven Documentation page and learn how to get start with maven more.