January 22, 2020
3min Read
Edward S.
Apache Maven is a free and 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. That’s a great tool for powering up your VPS project!
Apache Maven can help to manage projects and is most popular with Java.
There are many benefits of using Apache Maven, some of which are:
Maven makes it easier to manage various tasks, thus it’s smart to utilize it.
To install Maven 3.3 or above you need to have JDK 1.7 or above installed.
Maven can be installed in two ways:
Before installing java, you can update the package index for Ubuntu by using:
sudo apt update
Remember, first you need to access your VPS using SSH. If you’re having trouble, check out our PuTTY tutorial!
First, let’s see how to install Maven on Ubuntu from the Official website.
You can install the default Open JDK package for Ubuntu by using:
apt-get update
sudo apt install default-jdk
This might take a few minutes. Once this is complete, you can verify the Java installation by using:
java -version
This will show the installed Java version.
You can check the Maven official page to check the latest Maven version and download it using the wget command. You can download it to the /tmp directory, as shown below:
wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz -P /tmp
The file will be downloaded as a .tar.gz file. You can extract it to the /opt directory by using the command:
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
To ensure Maven is working properly, you need to configure a few environment variables, including JAVA_HOME, M3_HOME, MAVEN_HOME, and PATH.
To make this change create a file named maven.sh inside /etc/profile.d/ directory.
sudo vi /etc/profile.d/maven.sh
The configuration below needs to be added to this newly created file.
export JAVA_HOME=/usr/lib/jvm/default-java export M3_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
Save this file by hitting escape and then typing in :wq and provide the required privileges to the file using the command below:
sudo chmod +x /etc/profile.d/maven.sh
Keep in mind, that this command only configures the environment variables. To refresh and load it, use the command:
source /etc/profile.d/maven.sh
This is a simpler way to install Maven in Ubuntu since the official Ubuntu repositories contain Maven packages by default. However, keep in mind, that it may not be the latest Maven version.
As mentioned in the method above, you need to install Open JDK package to ensure everything runs properly.
Start by updating the package index by using:
sudo apt-get update
Next, you can install Maven using the command below:
sudo apt-get -y install maven
By default, it will be installed in /usr/share/maven and /etc/maven locations.
You can verify Maven installation by using the command below (works with both installation methods):
mvn -version
This will show the installed Apache Maven version.
Now you can start using Maven in your Ubuntu machine. You can test this by running an existing Maven project pom.xml file.
Maven certainly has several benefits when it comes to project management. You can use one of the two methods above to install Maven on Ubuntu 18.04.
Leave a reply