Install Apache Maven in Fedora 23

Prerequisite:

  • JDK must be installed in the system.
  • Download the binary tar .gz archive file from the Apache Maven website, i.e., from the location https://maven.apache.org/download.cgi. The file will look similar to “apache-maven-3.3.9-bin.tar.gz”.

Installation:

  1. Create a new folder say “apache-maven” inside the location “/usr/local/” by running the command:

    sudo mkdir -p /usr/local/apache-maven

  2. Move the downloaded “apache-maven-3.3.9-bin.tar.gz” file to the above created folder location by running the command:

    sudo mv apache-maven-3.3.9-bin.tar.gz /usr/local/apache-maven

  3. Go to the folder location:

    cd /usr/local/apache-maven

  4. Extract the contents of the archive file:

    sudo tar -xzvf apache-maven-3.3.9-bin.tar.gz

  5. You have to set some variables like M2_HOME, M2, MAVEN_OPTS and PATH, which can be done by editing either “.profile” or “.bash_profile” file in the user’s HOME folder, or editing “/etc/profile” file. Editing the files inside the HOME folder will effect the user’s shell, while editing “/etc/profile” will make the changes available system-wide.To edit the file the command will be:

    sudo gedit
    or,
    sudo vi

    For example, to edit “/etc/profile” the command will be

    sudo gedit /etc/profile
    or,
    sudo vi /etc/profile

    The above commands will open file for editing.

  6. Add the following contents at the end of the file mentioned in Step5:

    export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
    export M2=$M2_HOME/bin
    export MAVEN_OPTS=”-Xms256m -Xmx512m”
    export PATH=$M2:$PATH

    Note: The path mentioned in the 1st line to set M2_HOME should be the location where the file gets extracted in Step2.

  7. Execute the following command:

    sudo update-alternatives –install “/usr/bin/mvn” “mvn” “/usr/local/apache-maven/apache-maven-3.3.9/bin/mvn” 1

    Note: The file location “/usr/local/apache-maven/apache-maven-3.3.9/bin/mvn” should be present inside the extracted folder in Step2.

  8. Check the maven installation by running the command:

    mvn -version

    You should get the output similar to below:

    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
    Maven home: /usr/local/apache-maven-3.3.9
    Java version: 1.8.0_66, vendor: Oracle Corporation
    Java home: /usr/java/jdk1.8.0_66/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: “linux”, version: “4.2.3-300.fc23.x86_64”, arch: “amd64”, family: “unix”