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 CentOS/RHEL 8/7

    How To Install Apache Maven on CentOS/RHEL 8/7

    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 CentOS/RHEL 8/7 and Fedora 31/30/29 systems.

    Advertisement

    You may like:

    • How to Install Gradle on CentOS 8

    Step 1 – Prerequisite

    Java development kit is the primary requirement of Apache Maven. So you need to install the Java development kit (JDK) on your system. Make sure you have installed JDK, not JRE. se following command to install it.

    yum install java-11-openjdk
    

    Verify installed Java version on your system.

    java -version 
    
    openjdk version "11.0.6" 2020-01-14 LTS
    OpenJDK Runtime Environment 18.9 (build 11.0.6+10-LTS)
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10-LTS, mixed mode, sharing)
    

    If you don’t have Java Development Kit installed on your system. Visit Install Java 11 on CentOS/RHEL 7/6 and Fedora

    Step 2 – Install Apache Maven

    After verifying java version on your system. Download Apache Maven from its official website or use the following command to download Apache Maven 3.6.2.

    cd /opt
    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 maven
    

    Step 3 – Setup Environment Variables

    As you have downloaded precompiled 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/maven.sh
    

    and add the following content.

    export M2_HOME=/opt/maven
    export PATH=${M2_HOME}/bin:${PATH}
    

    Now load the environment variables in current shell using following command.

    source /etc/profile.d/maven.sh
    

    Step 4 – Check Maven Version

    Apache Maven has been successfully configured on your system. Use the following command to check the version of installed Maven on your system.

    mvn -version
    
    Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
    Maven home: /opt/maven
    Java version: 11.0.6, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.6.10-0.el8_1.x86_64
    Default locale: en_US, 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 the system to free disk space.

    rm -f apache-maven-3.8.5-bin.tar.gz
    

    Apache Apache Maven 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 41 Comments

    41 Comments

    1. Serguei on April 27, 2021 7:30 am

      Thank you for sharing. The only typo is in the last command when you remove the downloaded maven archive, – you took the 3.6.3 version but were removing 3.6.2 one.

      Reply
    2. Leon on January 12, 2021 9:38 pm

      Thanks, great guide!

      Reply
    3. kvn on December 30, 2020 7:30 pm

      How to uninstall maven on Redhat linux

      Reply
    4. Niyati on October 21, 2020 3:10 am

      Thank you! It was helpful!

      Reply
    5. Antonio Soares on May 14, 2020 8:43 pm

      Straight to the point! thanks so much!

      Reply
    6. Jai Gupta on February 16, 2020 5:27 am

      wget https://www-eu.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
      This link is not working. I think it is not on servers for me
      wget https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
      This worked please update the link and other commands according to it.

      Reply
    7. Pavan on November 6, 2019 6:45 am

      Slick and informative

      Reply
    8. HANSA on August 2, 2019 6:51 pm

      Could you please correct that mistake….sudo tar xzf aapache-maven-3.6.0-bin.tar.gz. => sudo tar xzf apache-maven-3.6.0-bin.tar.gz

      Reply
      • Rahul on August 3, 2019 6:25 am

        Thanks Hansa, Article has been updated

        Reply
    9. chetan tiwary on June 11, 2019 4:07 am

      Hello Rahul ,

      I am also a RHCE 🙂 Great to view your blog. helped so much at various places. Great going brother. all the best !

      Reply
    10. JASON on August 14, 2018 10:09 pm

      Very nice HowTo!

      Reply
    11. Phuoc Bui on August 3, 2018 1:14 am

      Nice, easy for newbie like me ^^!

      Reply
    12. Pavol on July 16, 2018 8:39 am

      Nice and easy! thanks so much

      Reply
    13. dave on May 23, 2018 10:18 pm

      Gracias desde Mexico

      Reply
    14. Lassa on April 14, 2018 2:37 pm

      Your are great

      Reply
    15. jijendiran on March 24, 2018 4:52 am

      Hi ,
      I have a doubt whether two different maven versions can be installed and used in same linux machine,Im using centos

      Reply
      • Rahul K. on March 28, 2018 7:32 am

        Yes, You can install different Maven version on the same machine. Extract the different Maven version to different-2 directories and create /etc/profile.d/maven-v1.sh and /etc/profile.d/maven-v2.sh with proper setup.

        Now use source the required Maven version configuration file and use.

        Reply
    16. Chandrashekar R Gaajula on March 20, 2018 8:13 pm

      Thanks for the instructions. I had to use a different link though -> http://mirrors.gigenet.com/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz

      Reply
      • Rahul K. on March 28, 2018 7:37 am

        Thank you so much. I have upgraded tutorial to the install Maven latest version on Linux.

        Reply
    17. M2f0 on February 16, 2018 11:43 am

      Great. Thanks for the help.

      Reply
    18. sree on January 25, 2018 9:33 pm

      Awesome. Thank you so much

      Reply
    19. Dipen Ved on January 17, 2018 5:30 pm

      GREAT BLOG DUDE!

      Reply
    20. Simon M. on January 13, 2018 4:13 pm

      Thanks man!!
      Very precise and concise steps to follow!!

      Reply
    21. nitin swarnkr on January 5, 2018 11:47 am

      Awesome. Very crisp and clean instructions.

      Reply
      • Rahul K. on January 22, 2018 6:07 am

        Thanks Nitin

        Reply
    22. Lalit on January 4, 2018 4:52 am

      Thanks

      Reply
    23. Marcos on December 12, 2017 1:22 pm

      Thanks!!!!

      Reply
    24. sushant on October 31, 2017 6:19 pm

      Getting below error , even though it’s pointing to correct JDK
      [[email protected] ~]$ echo $JAVA_HOME
      /usr/java/jdk1.8.0_25/
      [[email protected] ~]$ mvn -version
      The JAVA_HOME environment variable is not defined correctly
      This environment variable is needed to run this program
      NB: JAVA_HOME should point to a JDK not a JRE
      [[email protected] ~]$

      Reply
      • sushant on October 31, 2017 6:32 pm

        My bad, $JAVA_HOME path was wrong, actually i had copy pasted this path, later found out that jdk version was different.

        Thanks

        Reply
        • Rahul K. on November 1, 2017 5:12 am

          Sounds good Sushant. It’s working for you.

          Reply
    25. Matias on October 23, 2017 8:07 pm

      Nice post.

      Reply
    26. dude on October 17, 2017 1:12 pm

      Worked like a charm on centos 6.9, thanks!

      Reply
    27. abhishek on September 22, 2017 5:22 pm

      your script in set up environment variable is faulty
      export M2_HOME=/opt/maven
      export PATH=${M2_HOME}/bin:${PATH}

      its should include maven version also
      correct command is :—
      export M2_HOME=/opt/maven/apache-maven-3.5.0
      export PATH=${M2_HOME}/bin:${PATH}

      Reply
      • Rahul K. on September 28, 2017 6:29 am

        Hi Abhishek,

        The tutorial has created a softlink of /opt/apache-maven-3.5.0 to /opt/maven in Step 2.

        Reply
    28. Frank on September 19, 2017 11:20 pm

      Nice job! Works great.

      Reply
    29. K on September 18, 2017 11:23 am

      thanks !!

      Reply
    30. Ela on May 20, 2017 3:55 pm

      Thank You!

      Reply
    31. Anuj on May 17, 2017 8:48 am

      very nice

      Reply
    32. e on April 25, 2017 7:04 pm

      gracias

      Reply
    33. Pavel on March 22, 2017 3:17 am

      Thank you for a great tutorial!

      Reply
    34. Dan on February 8, 2017 3:41 pm

      Thank You!

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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