• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

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

Written by Rahul, Updated on April 19, 2020

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.

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-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Now extract downloaded archive using following command.

sudo tar xzf apache-maven-3.6.3-bin.tar.gz
sudo ln -s apache-maven-3.6.3 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.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
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.6.2-bin.tar.gz

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

40 Comments

  1. Avatar Leon Reply
    January 12, 2021 at 9:38 pm

    Thanks, great guide!

  2. Avatar kvn Reply
    December 30, 2020 at 7:30 pm

    How to uninstall maven on Redhat linux

  3. Avatar Niyati Reply
    October 21, 2020 at 3:10 am

    Thank you! It was helpful!

  4. Avatar Antonio Soares Reply
    May 14, 2020 at 8:43 pm

    Straight to the point! thanks so much!

  5. Avatar Jai Gupta Reply
    February 16, 2020 at 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.

  6. Avatar Pavan Reply
    November 6, 2019 at 6:45 am

    Slick and informative

  7. Avatar HANSA Reply
    August 2, 2019 at 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

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

      Thanks Hansa, Article has been updated

  8. Avatar chetan tiwary Reply
    June 11, 2019 at 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 !

  9. Avatar JASON Reply
    August 14, 2018 at 10:09 pm

    Very nice HowTo!

  10. Avatar Phuoc Bui Reply
    August 3, 2018 at 1:14 am

    Nice, easy for newbie like me ^^!

  11. Avatar Pavol Reply
    July 16, 2018 at 8:39 am

    Nice and easy! thanks so much

  12. Avatar dave Reply
    May 23, 2018 at 10:18 pm

    Gracias desde Mexico

  13. Avatar Lassa Reply
    April 14, 2018 at 2:37 pm

    Your are great

  14. Avatar jijendiran Reply
    March 24, 2018 at 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

    • Rahul Rahul K. Reply
      March 28, 2018 at 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.

  15. Avatar Chandrashekar R Gaajula Reply
    March 20, 2018 at 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

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

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

  16. Avatar M2f0 Reply
    February 16, 2018 at 11:43 am

    Great. Thanks for the help.

  17. Avatar sree Reply
    January 25, 2018 at 9:33 pm

    Awesome. Thank you so much

  18. Avatar Dipen Ved Reply
    January 17, 2018 at 5:30 pm

    GREAT BLOG DUDE!

  19. Avatar Simon M. Reply
    January 13, 2018 at 4:13 pm

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

  20. Avatar nitin swarnkr Reply
    January 5, 2018 at 11:47 am

    Awesome. Very crisp and clean instructions.

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

      Thanks Nitin

  21. Avatar Lalit Reply
    January 4, 2018 at 4:52 am

    Thanks

  22. Avatar Marcos Reply
    December 12, 2017 at 1:22 pm

    Thanks!!!!

  23. Avatar sushant Reply
    October 31, 2017 at 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] ~]$

    • Avatar sushant Reply
      October 31, 2017 at 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

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

        Sounds good Sushant. It’s working for you.

  24. Avatar Matias Reply
    October 23, 2017 at 8:07 pm

    Nice post.

  25. Avatar dude Reply
    October 17, 2017 at 1:12 pm

    Worked like a charm on centos 6.9, thanks!

  26. Avatar abhishek Reply
    September 22, 2017 at 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}

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

      Hi Abhishek,

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

  27. Avatar Frank Reply
    September 19, 2017 at 11:20 pm

    Nice job! Works great.

  28. Avatar K Reply
    September 18, 2017 at 11:23 am

    thanks !!

  29. Avatar Ela Reply
    May 20, 2017 at 3:55 pm

    Thank You!

  30. Avatar Anuj Reply
    May 17, 2017 at 8:48 am

    very nice

  31. Avatar e Reply
    April 25, 2017 at 7:04 pm

    gracias

  32. Avatar Pavel Reply
    March 22, 2017 at 3:17 am

    Thank you for a great tutorial!

  33. Avatar Dan Reply
    February 8, 2017 at 3:41 pm

    Thank You!

Leave a Reply Cancel reply

Popular Posts

  • How to View or List Cron Jobs in Linux
  • How to Install PHP 8 on Ubuntu 20.04
  • How to Set Up SSH Tunnel with PuTTY
  • How to Install Tor Browser on Ubuntu 20.04
  • Issue with phpMyAdmin and PHP: Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable”
  • How to Allow Remote Connections to MySQL
  • How to Install MySQL 8.0 on Ubuntu 20.04
  • How to Install Apache Kafka on Ubuntu 20.04
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy