# Maven Installation on the Ubuntu

Perform updates on the server

```bash
sudo apt-get update 
```

***The*** Java-based products (Artifactory, Distribution, Insight, Mission Control) must run with **JDK 17+. So, it's better to install OpenJDK 17 on the node. OpenJDK 17 with Maven 3.9.5 works !! TESTED !!**

if java is already installed on the server, check the version, with the command

```bash
java --version
```

* Download the latest Apache Maven version
    
    ```bash
    wget https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz
    ```
    
* once downloaded extract the Apache Maven setup in /opt directory
    
    ```bash
     sudo tar xf apache-maven-3.9.5-bin.tar.gz -C /opt
    ```
    
* Create a symlink for Apache maven directory to update the maven versions
    
    ```bash
    sudo ln -s /opt/apache-maven-3.9.5 /opt/maven
    ```
    
* To set up apache maven environment variables in Ubuntu 20.04 LTS, create a file named [**maven.sh**](http://maven.sh) in **/etc/profile.d/** directory
    
* ```bash
    sudo nano /etc/profile.d/maven.sh
    ```
    
* Paste the below lines
    
* ```bash
    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
    export M2_HOME=/opt/maven
    export MAVEN_HOME=/opt/maven
    export PATH=${M2_HOME}/bin:${PATH}
    ```
    
* Give the executable permission using chmod
    
* ```bash
    sudo chmod +x /etc/profile.d/maven.sh
    ```
    
* Load the Environment Variables using the **source** command
    
* ```bash
    source /etc/profile.d/maven.sh
    ```
    
* Verify the installed Maven version using the command line
    
* ```bash
    mvn -version
    ```
    

### Troubleshooting Maven

* Imagine, you are not able to find the Java version and install mlocate to locate the files in the server
    
    ```bash
    sudo apt install mlocate
    ```
    
* then run *locate java*
    
* In the result search */usr/lib/jvm/*
    
* observe the folder name of the OpenJDK version. Now, set this path in the environments variables for JAVA\_HOME and then continue the steps to have a happy maven installation!
