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:
Step 1 – Prerequisites
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 Ubuntu
After 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-maven
Step 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.sh
Step 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.
8 Comments
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export M2_HOME=/usr/local/apache-maven
export MAVEN_HOME=/usr/local/apache-maven
export PATH=${M2_HOME}/bin:${PATH}
if you have installed maven from Ubuntu 16 package, $MAVEN_HOME=/usr/share/maven
I followed the steps and I could get following output.
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T00:03:14+05:30)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_101, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: “linux”, version: “3.16.0-40-generic”, arch: “amd64”, family: “unix”
But when I opened a new terminal and type mvn -version I get the following error.
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
i am on Ubuntu and followed your instructions with the exception that i put the export statements in my .profile
it works, but is that wrong?
i also do not know how the system is finding the commands “java” and “mvn” without having $JAVA_HOME/bin:$MAVEN_HOME/bin in my path
please explain, thanks
Hi Dan,
Please check the Step 3. You will find that all environment variables including PATH are configured in /etc/profile.d/apache-maven.sh file. Which is automatically loaded by the system during startup.
can anyone say how to remove this maven ……………..
even i used the remove command its not working and if i check the version again i get the same as maven 3.3.9…..
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: “linux”, version: “4.2.0-42-generic”, arch: “amd64”, family: “unix”
I followed your instructions as it is. All steps done, but in the end when I do mvn -version I get the error
-bash: mvn: command not found
Please help
How am I supposed to read this with the banner on the side covering up writing?