Apache Maven is a Build Automation Tool. Alternative technologies is Gradle and sbt as build tools. We published guide on how to install Gradle. Maven needs XML file to build. Gradle and sbt do not rely on XML, but basic concept is like Maven introduced. Maven Needed For Many Big Data Software. Here Are the Steps on How To Install Apache Maven on Ubuntu Server. Maven takes care of two aspects of building software – describing how the software is built and its dependencies. Apache Ant is older and only exceptions need to be written down. Apache Ivy is next step of Apache Ant, Apache Maven, Gradle with dedicated dependency manager and support for Maven repositories. Still we need Maven instead of Ivy for many reasons. Maven projects are configured using a Project Object Model (POM), stored in a pom.xml
file like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <project> <!-- model version is always 4.0.0 for Maven 2.x POMs --> <modelVersion>4.0.0</modelVersion> <!-- project coordinates, i.e. a group of values which uniquely identify this project --> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0</version> <!-- library dependencies --> <dependencies> <dependency> <!-- coordinates of the required library --> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <!-- this dependency is only used for running and compiling tests --> <scope>test</scope> </dependency> </dependencies> </project> |
Steps To Install Apache Maven on Ubuntu Server
Update, Upgrade and install the software-properties-common package :
1 2 3 | apt update -y apt upgrade -y apt install software-properties-common apt-transport-https -y |
Add the ‘webupd8team’ PPA repository to the server :
---
1 2 | sudo add-apt-repository ppa:webupd8team/java -y apt upgrade |
Install the Java 8 installer from the PPA repository :
1 | apt install oracle-java8-installer -y |
Accept the Oracle License by choosing the ‘YES’ button. Check the java version :
1 | java -version |
Download latest Apache Maven binary code. We are using /opt/apache-maven
directory as the Maven home directory and Maben 3.5.3 as example.
1 2 3 4 | cd /opt/ wget http://www-eu.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz tar -xzvf apache-maven-3.5.3-bin.tar.gz mv apache-maven-3.5.3/ apache-maven/ |
Go to the /etc/profile.d
directory and create a new configuration file maven.sh
:
1 2 | cd /etc/profile.d/ nano maven.sh |
Copy-paste the following configuration :
1 2 3 4 5 6 | # Apache Maven Environment Variables # MAVEN_HOME for Maven 1 - M2_HOME for Maven 2 export JAVA_HOME=/usr/lib/jvm/java-8-oracle export M2_HOME=/opt/apache-maven export MAVEN_HOME=/opt/apache-maven export PATH=${M2_HOME}/bin:${PATH} |
Save the changes and exit. Run the next needed commands :
1 2 | chmod +x maven.sh source maven.sh |
To verify the maven installation, we can run the following Maven commands :
1 2 | mvn --version mvn --help |
You will get official help, documentations at :
1 | https://maven.apache.org/run.html |