{"id":2912,"date":"2018-02-20T14:33:46","date_gmt":"2018-02-20T11:33:46","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/ubuntu-apache-maven-installation\/"},"modified":"2018-02-20T14:33:46","modified_gmt":"2018-02-20T11:33:46","slug":"how-to-install-apache-maven-on-ubuntu-16-04-lts","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/how-to-install-apache-maven-on-ubuntu-16-04-lts\/","title":{"rendered":"How to Install Apache Maven on Ubuntu 16.04 LTS"},"content":{"rendered":"<p>Apache Maven is a software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects. It can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.<\/p>\n<p>In this tutorial, I will show you step-by-step how to install and configure Apache Maven on Ubuntu 16.04. We will also learn how to install Java 8 from the PPA Repository.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>Ubuntu 16.04<\/li>\n<li>Root privileges<\/li>\n<\/ul>\n<h2 id=\"what-we-will-do\">What we will do<\/h2>\n<ol>\n<li>Install Java on Ubuntu 16.04<\/li>\n<li>Download Apache Maven<\/li>\n<li>Configure Apache Maven Environment<\/li>\n<li>Testing<\/li>\n<\/ol>\n<h2 id=\"step-install-java-on-ubuntu-\">Step 1 &#8211; Install Java on Ubuntu 16.04<\/h2>\n<p>In this tutorial, we will be using the Java packages from the PPA repository, so we need to add the Java PPA Repository to the system.<\/p>\n<p>Before adding a new repository, install the &#8216;python-software-properties&#8217; package using the apt command below.<\/p>\n<p class=\"command\">sudo apt install -y python-software-properties<\/p>\n<p>Now add the Java PPA repository and update all repositories.<\/p>\n<p class=\"command\">sudo add-apt-repository ppa:webupd8team\/java<br \/>sudo apt update<\/p>\n<p>Ubuntu repositories have been updated.<\/p>\n<p>Apache Maven requires the JDK 1.7 or above. And for this guide, we will install the JDK 1.8.<\/p>\n<p>Install java from PPA using the apt command below.<\/p>\n<p class=\"command\">sudo apt install -y oracle-java8-installer<\/p>\n<p>During the installation, you will be prompted about the Oracle Binary License. Choose &#8216;OK&#8217;.<\/p>\n<p><a class=\"fancybox\" id=\"img-1\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts.png\" alt=\"Accept Oracle Binary License\" width=\"500\" height=\"179\" title=\"\"><\/a><\/p>\n<p>Accept the Oracle License by choosing the &#8216;YES&#8217; button.<\/p>\n<p><a class=\"fancybox\" id=\"img-2\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts-1.png\" alt=\"License ok\" width=\"500\" height=\"101\" title=\"\"><\/a><\/p>\n<p>And when the installation is complete, check the java version using the command below.<\/p>\n<p class=\"command\">java -version<\/p>\n<p>You will see a result similar to the following.<\/p>\n<p><a class=\"fancybox\" id=\"img-3\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts-2.png\" alt=\"Check java version\" width=\"500\" height=\"138\" title=\"\"><\/a><\/p>\n<p>Java 8 installed on the Ubuntu 16.04 server.<\/p>\n<h2 id=\"step-download-apache-maven\">Step 2 &#8211; Download Apache Maven<\/h2>\n<p>In this step, we will download the apache maven binary code using the wget command. And we will be using the &#8216;\/usr\/local\/src&#8217; directory as the Maven home directory.<\/p>\n<p>Go to the &#8216;\/usr\/local\/src&#8217; directory and download the Apache Maven Binary code.<\/p>\n<p class=\"command\">cd \/usr\/local\/src<br \/>wget http:\/\/www-us.apache.org\/dist\/maven\/maven-3\/3.5.2\/binaries\/apache-maven-3.5.2-bin.tar.gz<\/p>\n<p>Extract the maven.tar.gz file, then delete the compressed file.<\/p>\n<p class=\"command\">tar -xf apache-maven-3.5.2-bin.tar.gz<br \/>rm -f apache-maven-3.5.2-bin.tar.gz<\/p>\n<p>And you will get new directory apache-maven-version &#8211; rename the directory.<\/p>\n<p class=\"command\">mv apache-maven-3.5.2\/ apache-maven\/<\/p>\n<p>Apache Maven is now downloaded in the &#8216;\/usr\/local\/src\/apache-maven&#8217; directory.<\/p>\n<p><a class=\"fancybox\" id=\"img-4\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts-3.png\" alt=\"Unpack Maven\" width=\"500\" height=\"164\" title=\"\"><\/a><\/p>\n<h2 id=\"step-configure-apache-maven-environment\">Step 3 &#8211; Configure Apache Maven Environment<\/h2>\n<p>In this step, we will configure the environment for Apache Maven. We will define some environment variables that are needed by the Apache Maven, including &#8216;JAVA_HOME&#8217;, M2_HOME, and the PATH environment for the maven binary files.<\/p>\n<p>Go to the &#8216;\/etc\/profile.d&#8217; directory and create a new configuration file &#8216;maven.sh&#8217;.<\/p>\n<p class=\"command\">cd \/etc\/profile.d\/<br \/>vim maven.sh<\/p>\n<p>Paste the following configuration there.<\/p>\n<pre class=\"system\"># Apache Maven Environment Variables<br\/># MAVEN_HOME for Maven 1 - M2_HOME for Maven 2<br\/>export JAVA_HOME=\/usr\/lib\/jvm\/java-8-oracle<br\/>export M2_HOME=\/usr\/local\/src\/apache-maven<br\/>export MAVEN_HOME=\/usr\/local\/src\/apache-maven<br\/>export PATH=${M2_HOME}\/bin:${PATH}<\/pre>\n<p>Save the changes and exit.<\/p>\n<p>Now make the &#8216;maven.sh&#8217; script executable and then apply the configuration by running the &#8216;source&#8217; command.<\/p>\n<p class=\"command\">chmod +x maven.sh<br \/>source maven.sh<\/p>\n<p>The Apache Maven environment setup has been completed.<\/p>\n<p><a class=\"fancybox\" id=\"img-5\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts-4.png\" alt=\"Setup Apache Maven\" width=\"500\" height=\"153\" title=\"\"><\/a><\/p>\n<h2 id=\"step-testing-maven\">Step 4 &#8211; Testing Maven<\/h2>\n<p>To verify the maven installation, we can run the maven command below.<\/p>\n<p class=\"command\">mvn &#8211;version<\/p>\n<p>And you should get the result as below.<\/p>\n<p><a class=\"fancybox\" id=\"img-6\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_ubuntu_1604\/big\/6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/how-to-install-apache-maven-on-ubuntu-16-04-lts-5.png\" alt=\"Test Apache Maven setup\" width=\"500\" height=\"151\" title=\"\"><\/a><\/p>\n<p>Apache Maven 3.2 installation has been completed. It&#8217;s running under Linux 64-bit, with Java 1.8 installed, and the Maven home directory is &#8216;\/usr\/local\/src\/apache-maven&#8217;.<\/p>\n<h2 id=\"reference\">Reference<\/h2>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache Maven is a software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects. It can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. In this tutorial, I will show you step-by-step how to &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2912","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2912"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2912\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}