How To Install Apache Maven on Ubuntu 18.04
Abstract: export M2_HOME=/usr/local/apache-mavenIf you don’t have Java Development Kit installed on your system. Visit install Java 11 on Ubuntu Step 2 – Instal
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 to install Apache Maven on your Ubuntu 19.10 LTS, 18.04 LTS, and 16.04 LTS systems.
You may like:
- How to Install Gradle on Ubuntu 18.04
First of all, you make sure that you installed appropriate Java on your system.Java is the primary requirement of installing Apache Maven on nix systems. So firstly you need to install Java on your system also make sure you have installed JDK and JRE both.
java -version openjdk 11.0.6 2020-01-14 OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1) OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)
If you don’t have Java Development Kit installed on your system. Visit install Java 11 on Ubuntu
Step 2 – Install Maven on UbuntuAfter verifying java version on your system. Download Apache maven from its official website or use following command to download Apache Maven 3.6.3.
cd /usr/local wget wget https://www-us.apache.org/dist/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
Now extract downloaded archive using following command.
sudo tar xzf apache-maven-3.8.5-bin.tar.gz sudo ln -s apache-maven-3.8.5 apache-mavenStep 3 – Setup Environment Variables
As you have downloaded pre compiled Apache Maven files on your system. Now set the environments variables by creating new file /etc/profile.d/maven.sh.
sudo vi /etc/profile.d/apache-maven.sh
and add following content.
export JAVA_HOME=/usr/lib/jvm/java-11-oracle export M2_HOME=/usr/local/apache-maven export MAVEN_HOME=/usr/local/apache-maven export PATH=${M2_HOME}/bin:${PATH}
Now load the environment variables in current shell using following command.
source /etc/profile.d/apache-maven.shStep 4 – Verify Installation
You have successfully installed and configured Apache Maven on your Ubuntu system. Use the following command to check the version of Maven.
mvn -version Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: /usr/local/apache-maven Java version: 11.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-oracle Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-147.3.1.el8_1.x86_64", arch: "amd64", family: "unix"
Finally, remove the downloaded archive file from local.
rm -f apache-maven-3.6.3-bin.tar.gz
To read more about Apache Maven visit here.