How to Install Apache Maven on Amazon Linux 2

You are currently viewing How to Install Apache Maven on Amazon Linux 2

What is Apache Maven?

Apache Maven is a build automation tool for Java projects. It is used to manage a project’s build, reporting, and documentation from a central piece of information. Maven uses a declarative approach to building control, in which the developer specifies what the desired outcome should be, rather than specifying the steps to achieve it. This allows Maven to handle much of the build process automatically, reducing the amount of work that the developer needs to do. Maven is based on the concept of a “project object model” (POM) and uses a set of plugins to execute tasks such as compiling code, running tests, and creating documentation.

Why Do People Use Apache Maven?

There are several reasons why people use Apache Maven:

  1. Simplifies the build process: Maven automates the build process, taking care of the details of the build so that the developer can focus on coding.
  2. Provides a uniform build system: Maven uses a standard directory layout and a standard build lifecycle, which makes it easier for developers to understand and work with projects built with Maven.
  3. Manages dependencies: Maven can automatically download required dependencies and libraries that a project depends on, and manage the version conflicts that can arise when working with multiple dependencies.
  4. Generates reports: Maven can generate reports on the project’s build, including information on the dependencies used, the testing results, and the project’s code quality.
  5. Integrates with other tools: Maven can be integrated with other tools, such as continuous integration servers, making it easy to automate the build process and deploy code to production.

Overall, Maven helps to make the build process more efficient and reliable, allowing developers to focus on what they do best: writing code.

Installation Instruction on Amazon Linux 2

First, update the Yum packages

sudo yum update -y

then run the following command to add the Maven repository

sudo wget -O /etc/yum.repos.d/epel-apache-maven.repo

To set the version number run this command

sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo

Next, run this command to install Apache Maven

sudo yum install -y apache-maven

Avoid these common mistakes

Here are some of the common mistakes people often make when installing Apache Maven on Amazon Linux 2:

  1. Incorrect Java Installation: Apache Maven requires Java Development Kit (JDK) to be installed and properly configured. Some people may install the Java Runtime Environment (JRE) instead, or they might not correctly set up the JAVA_HOME environment variable.
  2. Using an Incompatible Java Version: Maven may not work properly if an incompatible Java version is installed. It’s important to ensure that the correct version of Java, which is compatible with the Maven version being installed, is being used.
  3. Not Updating the System: Sometimes, people don’t update their Amazon Linux 2 instance before beginning the Maven installation. This can lead to dependencies not being updated and potential conflicts during the installation process.
  4. Incorrectly Setting PATH: Once Maven is installed, its bin directory needs to be added to the PATH environment variable. Failing to do so, or doing it incorrectly, is a common mistake.
  5. Skipping Verification of the Download: It’s recommended to verify the integrity of the downloaded Maven binary archive against the provided checksums. Skipping this step might lead to installing a corrupted or tampered version.
  6. Lack of Sufficient User Privileges: Trying to install Maven without the necessary administrative privileges can lead to failure or incomplete installation.
  7. Incorrect Extraction of Maven Archive: Some people may not correctly extract the Maven tar.gz file to the intended directory, which can lead to errors when trying to run Maven.
  8. Not Checking the Maven Version after Installation: After installing Maven, it’s good practice to verify the installation by checking the version of Maven. This is done by running the command mvn -version. If this step is skipped, one may not realize if there were issues during the installation.
  9. Inadequate System Resources: Although not common, Maven installation might face issues on systems with low disk space or RAM. The system requirements should be checked prior to installation.
  10. Ignoring Error Messages: Sometimes, users might overlook or ignore error messages during the installation process, which can lead to faulty Maven installations.

Remember, each of these mistakes can be easily avoided by carefully following an up-to-date, step-by-step guide for installing Maven on Amazon Linux 2.


In conclusion, Apache Maven is a popular build automation tool for Java projects that simplifies the build process, provides a uniform build system, manages dependencies, generates reports, and integrates with other tools. To install Maven on Amazon Linux 2, you will need to first update the package manager’s cache and install the JDK. Then, download the latest version of Maven from the Apache Maven website, extract the downloaded archive to the desired installation location, add the Maven bin directory to your PATH environment variable, and load the updated environment variables. You can then test the installation by running the “mvn -v” command. With these steps, you will have successfully installed Maven on Amazon Linux 2.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply