# Installing Maven on Ubuntu

Apache Maven is an open-source project management tool primarily used to develop Java applications. It incorporates a POM (Project Object Model) approach, which stores information about projects, configurations, and dependencies in an XML file.

**<mark>Step 1: Install OpenJDK</mark>**

Update the system's package repository

```plaintext
sudo apt update
```

Install the latest OpenJDK version

```plaintext
sudo apt install default-jdk -y
```

Verify the installation by checking the current OpenJDK version:

```plaintext
java -version
```

**<mark>Step 2: Download and Install Maven</mark>**

Download the Maven installation file to the `/tmp` directory using the `wget` cmd

```plaintext
wget https://dlcdn.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz -P /tmp
```

Once the download is complete, extract the installation file to the /opt directory:

```plaintext
sudo tar xf /tmp/apache-maven-3.9.8-bin.tar.gz -C /opt
```

Create a symbolic link leading to the Maven installation directory:

```plaintext
sudo ln -s /opt/apache-maven-3.9.8 /opt/maven
```

**<mark>Step 3: Set Up Environment Variables</mark>**

Create and open the [*maven.sh*](http://maven.sh) script file in the */etc/profile.d/* directory:

```plaintext
sudo nano /etc/profile.d/maven.sh
```

Add the following lines to the [*maven.sh*](http://maven.sh) file:

```plaintext
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
```

Use the chmod command to make the [maven.sh](http://maven.sh) file executable:

```plaintext
sudo chmod +x /etc/profile.d/maven.sh
```

Execute the [maven.sh](http://maven.sh) script file with the source command to set up the new environment variables:

```plaintext
source /etc/profile.d/maven.sh
```

**<mark>Step 4: Verify Maven Installation</mark>**

```plaintext
mvn -version
```
