How to install and configure Apache Maven on CentOS 7

Apache Maven is a free and open source project management tool mainly used for Java projects. Maven uses the Project Object Model (POM) which is basically an XML file containing information about the project, configuration details, dependencies, etc.

In this tutorial, we’ll show you two different ways to install Apache Maven on CentOS 7.

The official Debian repository contains Maven packages that can be installed using Yum group manager. This is the easiest way to install Maven on CentOS 7, but the version included in the repository may lag behind the latest Maven version.

To install the latest version of Maven, follow the instructions in the second part of this article, where we will download Maven from the official website.

Choose the installation method best suited to your project needs.

precondition

To install packages on your Debian system, you must be logged in as a user with sudo privileges.

Install Apache Maven on CentOS with Yum

Installing Maven on Debian using yum It is a simple and easy process.

  1. Start by updating the package index:
    sudo yum update
  2. Install Maven by typing the following command:
    sudo yum install maven
  3. Verify the installation by running the command:
    mvn -version

    The output will look like this:

    Apache Maven 3.0.5 (Red Hat 3.0.5-17)
    Maven home: /usr/share/maven
    Java version: 1.8.0_191, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-862.3.2.el7.x86_64", arch: "amd64", family: "unix"

At this point, Maven is installed on your system and you can start using it.

Install the latest version of Apache Maven

The following sections provide step-by-step instructions on how to install the latest version of Apache Maven on CentOS 7. We will download the latest version of Apache Maven from their official website.

See also  How to install and configure Ruby on CentOS 7

1. Install OpenJDK

Maven 3.3+ requires JDK 1.7 or later to be installed. We will be installing OpenJDK, which is the default Java development and runtime on CentOS 7.

Installing Java on CentOS 7 is very simple. Start by updating the package index:

sudo yum update

Install the OpenJDK package by typing:

sudo yum install java-1.8.0-openjdk

Verify the installation by running the following command:

java -version

The output will look like this:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

2. Download Apache Maven

At the time of writing this article, the latest version of Apache Maven is 3.6.0. Before proceeding with the next step, you should check the Maven download page to see if a newer version is available.

Start by downloading Apache Maven in the directory /tmp Use command wget next:

wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz -P /tmp

After the download is complete, extract the archive into the directory /opt:

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

To further control Maven versions and updates, we will create a symbolic link pointing to the Maven installation directory:

sudo ln -s /opt/apache-maven-3.6.0 /opt/maven

If you want to update Maven, you can simply extract the latest version and change the symlink to point to the latest version.

3. Set environment variables

Next, we need to set up environment variables. To do this, open a text editor and create a new file called mavenenv.sh in the /etc/profile.d/ directory.

sudo nano /etc/profile.d/maven.sh

Paste the following configuration:

export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save and close the file. This script will be used when the shell is started. Then make the script executable by typing:

sudo chmod +x /etc/profile.d/maven.sh

Finally load the environment variables with the command source :

source /etc/profile.d/maven.sh

4. Check the installation

To verify that Maven is installed correctly, use the command mvn -versionwhich will print the Maven version:

mvn -version

You will see output like the following:

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.3.2.el7.x86_64", arch: "amd64", family: "unix"

The latest version of Maven is now installed on CentOS 7 systems.

See also  How to install and configure R on CentOS 8

conclusion

You have successfully installed Apache Maven on your CentOS 7. You can now visit the official Apache Maven documentation page and learn how to get started with Maven.

Source link

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply