Close Menu
Java HelpsJava Helps
    What's Hot

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    • Home
    • How To
      1. Install
      2. Run
      3. Configure
      4. View All

      How to Install MySQL with phpMyAdmin on Ubuntu?

      December 4, 2022

      Install The Latest IntelliJ IDEA on Linux

      November 28, 2022

      Install The Latest Apache Maven on Linux

      November 27, 2022

      Install The Latest Oracle JDK on Linux

      November 27, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022

      How to Run Apache NiFi Docker on Mac M1?

      December 1, 2022

      How to Run Apache NiFi on Docker?

      December 1, 2022

      Create A New Maven Project In IntelliJ IDEA

      November 29, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      How to Set Proxy for Maven?

      December 6, 2022

      How to Create a Fat JAR Using Maven?

      December 5, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      Manage GitHub Artifact Storage Quota

      December 6, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022
    • Hello World
      1. Framework
      2. Library
      3. View All

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022
    • More
      • Privacy Policy
        • Java Helps
        • Android Apps
      • Contact US
      • About
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    Home » Install The Latest Apache Maven on Linux
    Apache Maven
    Apache Maven
    Install

    Install The Latest Apache Maven on Linux

    Gobinath LoganathanBy Gobinath LoganathanNovember 27, 2022Updated:December 7, 2022No Comments3 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Apache Maven requires no introduction to Java developers. Most Linux distributions have Apache Maven in their package repositories. However, installing from the repository may also install OpenJDK even if you already have Oracle JDK installed. Debian-based distributions like Ubuntu or Linux Mint carry a slightly older version of Apache Maven in their repository. This may cause unexpected errors when building complex Java projects because some of the plugins used in the project may not be compatible with an older version of Apache Maven. Therefore, I always recommend installing Apache Maven from the binary source and this article aims to help you get the latest version of Apache Maven installed on your Linux machine.

    Requirements

    Apache Maven requires either the Open Java Development Kit or Oracle Java Development Kit installed in your system. If you don’t have it already, follow this link to install the Oracle Java Development Kit on your computer.

    Install Oracle JDK

    Download Apache Maven

    Visit the official Apache Maven website and download the latest binary archive file. apache-maven-3.8.6-bin.tar.gz is used in this article. If you download a different version, change the commands accordingly.

    Download

    Installation

    Step 1:
    Open the terminal (Ctrl + Alt + T) and enter the following command to change the directory.

    cd /opt

    Step 2:
    Extract the apache-maven-3.8.6-bin.tar.gz file in the opt directory using the following command.

    sudo tar -xvzf ~/Downloads/apache-maven-3.8.6-bin.tar.gz

    The above command assumes the Apache Maven binary archive filename is apache-maven-3.8.6-bin.tar.gz and it is located in the ~/Downloads folder. If your downloaded file is in any other location, change the command according to your path.


    Setup The Environment

    Step 1:
    Enter the following command to open the environment variables file. According to your personal preference, you can choose any text editor instead of nano.

    sudo nano /etc/environment

    Step 2:
    In the opened file, add the following bin folders to the existing PATH variable. Note that the PATH variables must be separated by a colon.

    /opt/apache-maven-3.8.6/bin

    Append the following environment variable to the end of the file.

    M2_HOME="/opt/apache-maven-3.8.6"

    A sample environment file before making these changes would look like the following:

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

    The same file after making the changes should look like this:

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/apache-maven-3.8.6/bin"
    M2_HOME="/opt/apache-maven-3.8.6"

    Save the changes and close the editor. If you are using nano as in this article, the shortcut to save the changes is Ctrl + O; the shortcut to close nano is Ctrl + X. To learn more about setting environment variables and/or setting the environment variable without root privilege, check How to Set Environment Variables in Linux.


    Step 3:
    Update the mvn alternative shortcuts by running the following commands:

    sudo update-alternatives --install "/usr/bin/mvn" "mvn" "/opt/apache-maven-3.8.6/bin/mvn" 0
    sudo update-alternatives --set mvn /opt/apache-maven-3.8.6/bin/mvn

    Step 4:
    To verify the setup enter the following command and make sure that it prints the location of mvn command as you have provided in the previous step.

    update-alternatives --list mvn

    Step 5 (Optional):
    Run the following command to install the Maven Bash Completion if you are using Bash Shell. Zsh users can activate the Maven Plugin in the Oh My Zsh framework.

    sudo wget https://raw.githubusercontent.com/javahelps/maven-bash-completion/master/bash_completion.bash --output-document /etc/bash_completion.d/mvn

    Step 6:
    Restart the computer (or just log out and log in) and open a new terminal.


    Step 7:
    Enter the following command.

    mvn --version

    If you get the Apache Maven version 3.8.6 as the output, you have successfully installed Apache Maven on your Linux system. If you have any questions or feedback, please comment below.

    install linux maven
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    How to Set Proxy for Maven?

    December 6, 2022

    How to Create a Fat JAR Using Maven?

    December 5, 2022

    Create Scala Project with Maven in IntelliJ IDEA

    December 4, 2022

    How to Install MySQL with phpMyAdmin on Ubuntu?

    December 4, 2022

    Create A New Maven Project In IntelliJ IDEA

    November 29, 2022

    Install The Latest IntelliJ IDEA on Linux

    November 28, 2022
    Don't Miss
    Configure

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    IntelliJ Idea: the famous IDE for JVM languages including Java, Scala, and Kotlin. If you…

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    About Us
    About Us

    Java Helps is the platform to share all about the Java ecosystem. All the sample code available on Java Helps articles are published under Apache 2.0 License. Readers are free to use them according to the Apache 2.0 License.

    "The world is my town; its people my kinsmen."
    -Kaṉiyan Pūngunṟanār

    Email Us: www.javahelps@gmail.com

    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    New Comments

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

      Go to mobile version