Apache Maven is an open-source project management tool, based on the Project Object Model. Maven contains XML files also referred to as pom.xml which includes configuration details, project dependencies, and other data which can benefit your Linux based VPS projects.
In this article, we will be guiding you on the installation of Apache Maven in your VPS. The Linux distribution used in this guide is Ubuntu 18.04.
Step 1: Update package index
Firstly, access your VPS using SSH. Then run the following command in your Ubuntu terminal to update the package index.
sudo apt update
Step 2: Install Java
Use the following command to install the Open JDK package.
apt-get update
sudo apt install default-jdk
After the installation is completed, verify your Java installation using the following command.
java -version
You will see the version of the Java you had installed in the output.
Step 3: Install Apache Maven
Check the Maven official page for the latest version and use the wget command to download it. To download it to your /tmp directory, run the following command.
wget https:// www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz -P /tmp
To extract the downloaded file into the opt/ directory, run the following command.
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
Step 4: Maven Environment Setup
To make sure that Maven is working properly, a few environments including JAVA_HOME, M3_HOME, MAVEN_HOME, and PATH need to be configured. Firstly, run the following command to create a file named maven.sh in the /etc/profile.d/ directory.
sudo vi /etc/profile.d/maven.sh
After the maven.sh file is created, add the following lines into the file.
export JAVA_HOME=/usr/lib/jvm/default-java export M3_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M3_HOME}/bin:${PATH}
Make save changes and quit with :wq, then provide the neccesary privileges for the file with the following command.
sudo chmod +x /etc/profile.d/maven.sh
To refresh and load the file, run the following command.
source /etc/profile.d/maven.sh
With this, the Apache Maven installation is concluded. To verify which Maven was installed into your system, run the following command.
mvn -version