Contents
Apache Maven is a software project management and comprehension tool. Maven can manage a project's build, reporting and documentation from a central piece of information.
This tutorial will help you install and configure Apache Maven on Ubuntu 20.04 LTS systems.
Prerequisites
Apache Maven requires the Java language to run on any operating system. First of all, make sure Java is installed on your system. Also make sure you have installed both the JDK and JRE.
java -version openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
If the Java Development Kit is not installed on your system, use the following command to install it.
sudo apt install default-jdk
Step 1 – Install Maven on Ubuntu 20.04
You can download Apache Maven from the official website or use the following command to download Apache Maven 3.6.3 to your system.
cd /usr/local wget https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
Now extract the downloaded archive using the following command.
sudo tar xzf apache-maven-3.6.3-bin.tar.gz sudo ln -s apache-maven-3.6.3 maven
Step 2 – Set Up Environment Variables
Since you downloaded the precompiled Apache Maven files to your system, now set up the environment variables by creating a new file, /etc/profile.d/maven.sh .
sudo vi /etc/profile.d/maven.sh
Update the file with the following content:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export M2_HOME=/usr/local/maven export MAVEN_HOME=/usr/local/maven export PATH=${M2_HOME}/bin:${PATH}
Save and close your file.
Then load the environment variables in the current shell using the following command.
source /etc/profile.d/maven.sh
Step 3 – Verify the Installation
You have successfully installed and configured Apache Maven on your Ubuntu system. To find the installed Maven version, type:
mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/maven Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.4.0-26-generic", arch: "amd64", family: "unix"
Finally, clean up the disk by removing the downloaded archive file.
rm -f apache-maven-3.6.3-bin.tar.gz
Conclusion
In this tutorial, you learned how to install Apache Maven on an Ubuntu system.