Apache Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. Maven Apache simplifies the build process like ANT but it is too much advanced than ANT.
In this tutorial we will show you two different ways to install Apache Maven on Ubuntu 18.04 LTS / Ubuntu 16.04 LTS: Using the apt
package manager or by a source from the official website.
Prerequisites
You’ll need to be logged in as a user with sudo
privileges in order to install the Apache Maven.
Method 1./ Installing Apache Maven using APT
– Use the below commands to update the repository packages and install the Apache Maven:
$ sudo apt update $ sudo apt install maven
– Run the mvn -version
command too verify if Apache Maven is successfully installed:
$ mvn -version Apache Maven 3.5.2 Maven home: /usr/share/maven Java version: 10.0.2, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_US, platform encoding: ISO-8859-1 OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"
Method 2./ Installing Apache Maven From Source
1. Install Java
01- Java Development Kit (JDK) is required to install Apache Maven. Use the following command to Install JDK package:
$ sudo apt update $ sudo apt install default-jdk
– To verify that Java was successfully installed, run the following command:
$ java -version openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2, mixed mode)
2. Download Apache Maven
– First, go to the official Apache Maven download page and use the wget
command to download the latest version of Apache Maven.
$ wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz -P /tmp
– Let’s extract the archive in the /opt
directory like below:
$ sudo tar -xzvf /tmp/apache-maven-3.6.0-bin.tar.gz -C /opt
– Now, create a symbolic link maven
which will point to the Maven installation directory in our example is apache-maven-3.6.0
$ sudo ln -s /opt/apache-maven-3.6.0 /opt/maven
3. Setup environment variables
– Next, we’ll need to setup the environment variables. Open your text editor and create a new file named maven.sh
inside of the /etc/profile.d/
directory.
$ sudo vi /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/default-java export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
– Finally, load the new environment variables by typing:
$ source /etc/profile.d/maven.sh
4. Verify the installation
– So, to verify that Maven is successfully installed, use the mvn -version
command which will print the Maven version:
$ mvn -version Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z) Maven home: /opt/maven Java version: 10.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_US, platform encoding: ISO-8859-1 OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"
Conclusion
You have successfully installed Apache Maven on your Ubuntu 18.04 LTS / Ubuntu 16.04 LTS server. You might want to check the following guides:
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!