How to install Apache Maven on CentOS 8


Start by running CentOS updates

  1. Yum update
  2. Confirm the download with 'Y'.
  3. Wait until the update is finished.

Install required packages Maven 3.3+ require JDK 1.7 or above to execute. At the time of writing, Maven 3.6.3 is the latest version.

  1. Yum install java-11-openjdk-devel
  2. Confirm the download with 'Y'.
  3. Check if the installation succeeded with: java -version

Install Maven Now we are ready to install Maven.

  1. Download the Maven files with: wget
  2. Extract the files to /opt with: tar xf apache-maven-3.6.3-bin.tar.gz -C /opt
  3. Create a Symbolic Link so that it is easier to update Maven in the future: ln -s /opt/apache-maven-3.6.3 /opt/maven

Configuration Configuration of Maven

  1. Create the file named into /etc/profile.d/ with: nano /etc/profile.d/
  2. Fill the file with the following code:
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
  1. Save and exit the file.
  2. Make the file executable: chmod +x /etc/profile.d/
  3. Now load the file with: source /etc/profile.d/

To check if Maven is installed correctly use the following command: mvn -version

Maven is now installed onto your VPS.