Install apache maven on centos 8
Apache Maven is an open-source project management and comprehension tool used primarily for Java projects.It helps handling multiple projects, can integrate with various IDE software and simplifies build process.
prerquisites:
a) must be login with root user or user with sudo privileges.
b) Install java on your system.
Step 1: Install Java
we will install openjdk on centos 8 from the AppStream repository. There are many Oopenjdk versions provided by the AppStream repository.Here we will install version11.
[root@centos ~]# dnf search openjdk
[root@centos ~]# dnf install java-11-openjdk
once java is installed check java version by following command.
[root@centos ~]# java -version
openjdk version "11.0.5" 2019-10-15 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)
Step 2: Install Apache Maven
you can install maven with dnf or download latest version of maven from Maven official website with wget and extract with following commands.
[root@centos ~]# wget http://apachemirror.wuchna.com/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
[root@centos ~]# tar -xvzf apache-maven-3.6.3-bin.tar.gz
[root@centos ~]# mv apache-maven-3.6.3 /opt/maven
Step 3: Setup Environment variables
Next we will setup environment variables by creating maven.sh under /etc/profile.d directory.
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.5.10-2.el8_1.x86_64/
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Now make maven.sh script executable and load the environment variables in the current shell using below command
[root@centos ~]# chmod +x /etc/profile.d/maven.sh
[root@centos ~]# source /etc/profile.d/maven.sh
Step 4: Verify Maven version
Use the following command to check the version of installed Maven on your system.
[root@centos ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 11.0.5, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.5.10-2.el8_1.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-80.11.2.el8_0.x86_64", arch: "amd64", family: "unix"
That’s All. we have successfully installed Apache Maven on Centos 8.