Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»How To Install Apache Maven on Ubuntu 18.04

    How To Install Apache Maven on Ubuntu 18.04

    By RahulMay 26, 20222 Mins Read

    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.

    Advertisement

    You may like:

    • How to Install Gradle on Ubuntu 18.04

    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.

    Apache Apache Maven install mavel Maven
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Understanding 2>&1 in Bash: A Beginner’s Guide

    How to Choose the Best Shebang (#!) for Your Shell Scripts

    Modulus Operator (%) in Bash

    Using Modulus Operator (%) in Bash

    View 8 Comments

    8 Comments

    1. yogesh on August 10, 2021 6:48 am

      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}

      Reply
    2. CzarnyZajaczek on September 28, 2018 12:31 pm

      if you have installed maven from Ubuntu 16 package, $MAVEN_HOME=/usr/share/maven

      Reply
    3. Hasara Maithree on July 5, 2018 6:26 am

      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

      Reply
    4. dan coleman on November 20, 2017 9:28 pm

      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

      Reply
      • Rahul K. on November 21, 2017 4:35 am

        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.

        Reply
    5. karthi on October 5, 2017 7:52 am

      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”

      Reply
    6. Manika Bedi on May 5, 2017 11:30 am

      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

      Reply
    7. anonymous on February 11, 2017 2:14 pm

      How am I supposed to read this with the banner on the side covering up writing?

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.