• Recent blogs

    How to Install Apache Maven on CentOS 7

    How to Install Apache Maven on CentOS 7


    Apache Maven is a free and open-source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM), which is essentially an XML file containing information about the project, configuration details, the projects dependencies, and so on.

    In this tutorial, we will take you through two different ways to install Apache Maven on CentOS 7.

    The official CentOS 7 repositories contain Maven packages that can be installed with the "yum" package manager. This is the easiest way to install Maven on CentOS 7. but it may not be the latest maven repository available. To install the latest version of Maven  we will be downloading Maven from their official website.

    Choose the installation method that is suits you.

    With YUM:

    Installing Maven on CentOS 7 using yum is a simple.

    Install Maven by typing the following command in your terminal:

    yum install maven -y

    Verify the installation by typing the "mvn -version" command:

    mvn -version

    The output will look something like this:

    [root@dockerserver ~]# mvn -version
    Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
    Maven home: /opt/maven
    Java version: 1.8.0_242, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-1.8.0-openjdk-
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-1062.12.1.el7.x86_64", arch: "amd64", family: "unix"
    [root@dockerserver  ~]#

    That’s it. Maven is now installed.

    Install the Latest  of Apache Maven

    The following sections provide a step by step instructions about how to install the latest Apache Maven version on CentOS 7. We’ll be downloading the latest release of Apache Maven from their official website.

    1. Install OpenJDK
    Maven 3.3+ requires JDK 1.7 or above to be installed. We’ll install OpenJDK, which is the default Java development and runtime in CentOS 7.

    yum install java-1.8.0-openjdk -y

    Verify that Java was successfully installed :

    [root@dockerserver  ~]# java -version
    openjdk version "1.8.0_242"
    OpenJDK Runtime Environment (build 1.8.0_242-b08)
    OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
    [root@dockerserver  ~]#

    2. Download Apache Maven

    Download latest Maven:

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

    Once the download is completed, extract the archive in the /opt directory:

    root@dockerserver :/# tar xf /tmp/apache-maven-*.tar.gz -C /opt

    root@dockerserver :/# ln -s /opt/apache-maven-3.6.3 /opt/maven

    Later if you want to upgrade your Maven installation you can simply unpack the newer version and change the symlink to point to the latest version.

    3. Setup environment variables

    update your profile file with following details:

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

    Reload the environment variables :

    source /etc/profile

    4. Verify the installation

    To validate that Maven is installed properly use following command

    mvn -version

    You should see something like the following:

    Apache Maven 3.6.3
    Maven home: /usr/share/maven
    Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /opt/openjdk
    Default locale: en, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-957.1.3.el7.x86_64", arch: "amd64", family: "unix"

    How to Install Apache Maven on Ubuntu

    No comments