The cart is empty

Apache Maven is a project management and build automation tool widely used among Java developers. Maven simplifies the building of Java projects by handling dependency management, project building, and test automation. In this article, we will look at the steps required to install Maven on a server.

Prerequisites

Before we begin with Maven installation, make sure your server meets the following prerequisites:

  • Installed JDK (Java Development Kit) version 8 or higher.
  • Access to the server with superuser privileges or a user with sufficient permissions to install software.

Step 1: Verify Installed Java

Before installing Maven, it's necessary to verify whether JDK is installed on the server. This can be done by running the following command in the terminal:

java -version

If JDK is installed, you should see the Java version. If not, you need to install JDK first.

Step 2: Download Maven

You can download the latest version of Maven from the official Apache Maven website. Use the following command to download Maven to your server:

wget https://archive.apache.org/dist/maven/maven-3/<maven_version>/binaries/apache-maven-<maven_version>-bin.tar.gz

Replace <maven_version> with the current version of Maven you want to install.

Step 3: Extract the Downloaded Archive

After downloading the Maven archive, you can extract the file to a suitable location on the server using the following command:

tar xzvf apache-maven-<maven_version>-bin.tar.gz -C /opt

Step 4: Set Environment Variables

To use Maven from any location in the system, it's necessary to set environment variables. This can be done by adding Maven binary files to the system path. Open the .bashrc or .profile file in your home directory and add the following lines:

export MAVEN_HOME=/opt/apache-maven-<maven_version>
export PATH=$PATH:$MAVEN_HOME/bin

After adding these lines, apply the changes by running:

source ~/.bashrc

Step 5: Verify Maven Installation

After completing the installation and setup, you can verify that Maven has been successfully installed by running:

mvn -version

If everything is set up correctly, you should see information about the Maven version and the installed JDK.

 

Installing Maven on a server is a straightforward process that involves several steps: verifying the installed JDK, downloading Maven, extracting the archive, setting environment variables, and verifying the installation. With Maven installed on your server, you are now ready to automate the building and management of your Java projects.