{"id":16048,"date":"2019-03-18T12:23:11","date_gmt":"2019-03-18T12:23:11","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16048"},"modified":"2024-06-26T07:43:19","modified_gmt":"2024-06-26T07:43:19","slug":"how-to-install-maven-on-ubuntu","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-install-maven-on-ubuntu","title":{"rendered":"How to Install Maven on Ubuntu: Using Apt and Official Website"},"content":{"rendered":"<p>Software development is one of the most challenging areas to work in. Fortunately, the right tools can make the development process more streamlined and efficient.<\/p><p>Apache Maven is a build automation tool mostly used for Java projects. It focuses on the simplification and standardization of the building process. One of Maven&rsquo;s main aspects is providing a comprehensive, maintainable, and simple model for projects.<\/p><p>This tutorial will cover the two methods of installing Apache Maven on Ubuntu and how to set up an environment for it.<\/p><p><strong>A Brief Overview of Installing Maven on Ubuntu:<\/strong><\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td>Required Knowledge<\/td><td>Basic Ubuntu server management, Java installation<\/td><\/tr><tr><td>Privileges Required<\/td><td>Root or sudo user privileges<\/td><\/tr><tr><td>Difficulty<\/td><td>Intermediate<\/td><\/tr><tr><td>Main Goal<\/td><td>Installing Apache Maven using APT and directly from the official website<\/td><\/tr><\/tbody><\/table><\/figure><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n\n\n<div class=\"protip\">\n                    <h2 class=\"featured-snippet title\">What Is Apache Maven?<\/h2>\n                    <p>Apache Maven is a free and open-source project management tool based on the Project Object Model (POM). Maven contains XML files or pom.xml, which include configuration details and project dependencies. Maven automates building, publishing, and deploying stages. It lets you work and manage several projects simultaneously.<\/p>\n                <\/div>\n\n\n\n<\/p><p>Here are the main benefits of Apache Maven:<\/p><ul class=\"wp-block-list\">\n<li>Extensive dependency management.<\/li>\n\n\n\n<li>Provides a standardized project structure to streamline team collaboration.<\/li>\n\n\n\n<li>Automatic dependency updates.<\/li>\n\n\n\n<li>Lets you download third-party libraries.<\/li>\n\n\n\n<li>Occupies less project space than other similar tools.<\/li>\n\n\n\n<li>Centralizes all configurations in a single XML file.<\/li>\n\n\n\n<li>More efficient debugging.<\/li>\n\n\n\n<li>Lets you remove duplicate dependencies.<\/li>\n\n\n\n<li>Offers detailed analysis of project dependencies and reports missing ones.<\/li>\n\n\n\n<li>Easy to test and deploy.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-install-apache-maven-on-ubuntu\">How to Install Apache Maven on Ubuntu<\/h2><p>Before installing Apache Maven, your system must meet the following requirements:<\/p><ul class=\"wp-block-list\">\n<li>User with sudo privileges<\/li>\n\n\n\n<li>OpenJDK 1.7 or above installed on your computer or virtual private server<\/li>\n\n\n\n<li>SSH client if you are using <a href=\"\/in\/vps-hosting\">VPS services<\/a><\/li>\n<\/ul><p>Users can install Apache Maven using the Advanced Package Tool (APT) or through the official Apache Maven website.<\/p><p>Let&rsquo;s start with the APT method.<\/p><h3 class=\"wp-block-heading\" id=\"h-method-1-install-apache-maven-on-ubuntu-using-apt\">Method 1. Install Apache Maven on Ubuntu Using APT<\/h3><p>The official Ubuntu repositories contain Maven packages by default. Thus, the most convenient way to install Apache Maven is by using the APT package manager.<\/p><p>However, the Maven package version in Ubuntu repositories may differ from the official one. It may also not be the latest release.<\/p><ol class=\"wp-block-list\">\n<li>Update the package index with the following <a href=\"\/in\/tutorials\/linux-commands\">Linux command<\/a>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get update<\/pre><ol class=\"wp-block-list\" start=\"2\">\n<li>Install OpenJDK:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install default-jdk<\/pre><ol class=\"wp-block-list\" start=\"3\">\n<li>Verify the installation by running the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">java -version<\/pre><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven.png\"><img decoding=\"async\" width=\"1024\" height=\"151\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven-1024x151.png\" alt=\"The terminal window displays version of newly installed OpenJDK that is necessary to install Maven\" class=\"wp-image-76426\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven-1024x151.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven-300x44.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven-150x22.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven-768x113.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-version-of-newly-installed-OpenJDK-that-is-necessary-to-install-Maven.png 1124w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"4\">\n<li>Install Maven using the command below:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get -y install maven<\/pre><p>The default Maven installation directories are <strong>\/usr\/share\/maven <\/strong>and <strong>\/etc\/maven<\/strong>. Verify the Apache Maven version using the following command:<\/p><pre class=\"wp-block-preformatted\">mvn -version<\/pre><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven.png\"><img decoding=\"async\" width=\"974\" height=\"226\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven.png\" alt=\"The terminal window displays the successful installation of the latest version of Apache Maven\" class=\"wp-image-76427\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven.png 974w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven-300x70.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven-150x35.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/The-terminal-window-displays-the-successful-installation-of-the-latest-version-of-Apache-Maven-768x178.png 768w\" sizes=\"(max-width: 974px) 100vw, 974px\" \/><\/a><\/figure><\/div><p>If you see a similar window, you&rsquo;ve successfully installed Apache Maven on your machine.<\/p><h3 class=\"wp-block-heading\" id=\"h-method-2-install-maven-on-ubuntu-using-the-official-website\">Method 2. Install Maven on Ubuntu Using the Official Website<\/h3><p>The second method is to install Maven from the official Apache website.<\/p><p><strong>Java Installation<\/strong><\/p><ol class=\"wp-block-list\">\n<li>Enter the following commands to update the package index and install the default OpenJDK package.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get update\n\nsudo apt install default-jdk<\/pre><p>The installation might take a few minutes to complete.<\/p><ol class=\"wp-block-list\" start=\"2\">\n<li>Verify the OpenJDK version using the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">java -version<\/pre><p>The terminal will display the installed Java version.<\/p><p><strong>Download Apache Maven<\/strong><\/p><ol class=\"wp-block-list\">\n<li>Open the Maven official page to check the latest release. At the time of writing, the latest release is 3.8.7. Download it using the <strong>wget <\/strong>command to the <strong>\/tmp <\/strong>Maven installation directory:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">wget https:\/\/dlcdn.apache.org\/maven\/maven-3\/3.8.7\/binaries\/apache-maven-3.8.7-bin.tar.gz -P \/tmp<\/pre><ol class=\"wp-block-list\" start=\"2\">\n<li>Extract the newly downloaded <strong>tar.gz <\/strong>file to the <strong>\/opt<\/strong> directory with the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo tar xf \/tmp\/apache-maven-*.tar.gz -C \/opt<\/pre><ol class=\"wp-block-list\" start=\"3\">\n<li>To ensure Maven works properly, configure a few <a href=\"\/in\/tutorials\/linux-environment-variables\">environment variables<\/a>, including <strong>JAVA_HOME<\/strong>, <strong>M3_HOME<\/strong>, <strong>MAVEN_HOME<\/strong>, and <strong>PATH<\/strong>. To do this, create a file named <strong>Maven.sh<\/strong> inside <strong>\/etc\/profile.d\/<\/strong> directory with your preferred text editor.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo nano \/etc\/profile.d\/maven.sh<\/pre><ol class=\"wp-block-list\" start=\"4\">\n<li>Fill in the file with the following environment variables: export JAVA_HOME=\/usr\/lib\/jvm\/default-java<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export JAVA_HOME=\/usr\/lib\/jvm\/default-java\nexport M3_HOME=\/opt\/maven\nexport MAVEN_HOME=\/opt\/maven\nexport PATH=${M3_HOME}\/bin:${PATH}<\/pre><ol class=\"wp-block-list\" start=\"5\">\n<li>Save this file and provide the required execute privileges:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo chmod +x \/etc\/profile.d\/maven.sh<\/pre><ol class=\"wp-block-list\" start=\"6\">\n<li>Refresh and execute the file with the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">source \/etc\/profile.d\/maven.sh<\/pre><ol class=\"wp-block-list\" start=\"7\">\n<li>Confirm the Maven installation by checking its version with the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">mvn -version<\/pre><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Apache Maven is a great tool to improve project management and make the development process much smoother.<\/p><p>In this tutorial, we&rsquo;ve covered two methods to install Maven on Ubuntu and showed you how to set up environment variables for it.<\/p><p>We hope that you found this tutorial useful. If you have any questions or insights, leave them in the comments below.<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Learn What Else Your Ubuntu System Can Do<\/h4>\n                    <p><a href=\"\/in\/tutorials\/how-to-list-installed-packages-on-ubuntu\/\">How to List Packages in Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-change-timezone-in-ubuntu\/\">How to Change Timezone in Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-see-system-users-in-ubuntu-linux-vps\/\">How to List Users in Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/install-pip-in-ubuntu\/\">How to Install Python Pip on an Ubuntu System<\/a><br>\n<a href=\"\/in\/tutorials\/linux-change-hostname\">How to Change Hostname in Linux<\/a><br>\n<a href=\"\/in\/tutorials\/install-java-ubuntu\">How to Install Java on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-jenkins-on-ubuntu\/\">How to Install Jenkins on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-node-ubuntu\">How to Install Node on Ubuntu<\/a><\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Software development is one of the most challenging areas to work in. Fortunately, the right tools can make the development process more streamlined and efficient. Apache Maven is a build automation tool mostly used for Java projects. It focuses on the simplification and standardization of the building process. One of Maven&rsquo;s main aspects is providing [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-install-maven-on-ubuntu\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22642,22640],"tags":[],"class_list":["post-16048","post","type-post","status-publish","format-standard","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/install-maven-ubuntu","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/installer-maven-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/install-maven-ubuntu","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-maven-on-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-maven-on-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=16048"}],"version-history":[{"count":20,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16048\/revisions"}],"predecessor-version":[{"id":112035,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16048\/revisions\/112035"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=16048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=16048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=16048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}