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:
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
41 Comments
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.
Thanks, great guide!
How to uninstall maven on Redhat linux
Thank you! It was helpful!
Straight to the point! thanks so much!
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.
Slick and informative
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
Thanks Hansa, Article has been updated
Hello Rahul ,
I am also a RHCE 🙂 Great to view your blog. helped so much at various places. Great going brother. all the best !
Very nice HowTo!
Nice, easy for newbie like me ^^!
Nice and easy! thanks so much
Gracias desde Mexico
Your are great
Hi ,
I have a doubt whether two different maven versions can be installed and used in same linux machine,Im using centos
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.
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
Thank you so much. I have upgraded tutorial to the install Maven latest version on Linux.
Great. Thanks for the help.
Awesome. Thank you so much
GREAT BLOG DUDE!
Thanks man!!
Very precise and concise steps to follow!!
Awesome. Very crisp and clean instructions.
Thanks Nitin
Thanks
Thanks!!!!
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] ~]$
My bad, $JAVA_HOME path was wrong, actually i had copy pasted this path, later found out that jdk version was different.
Thanks
Sounds good Sushant. It’s working for you.
Nice post.
Worked like a charm on centos 6.9, thanks!
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}
Hi Abhishek,
The tutorial has created a softlink of /opt/apache-maven-3.5.0 to /opt/maven in Step 2.
Nice job! Works great.
thanks !!
Thank You!
very nice
gracias
Thank you for a great tutorial!
Thank You!