Support >
  About cybersecurity >
  The complete guide to installing Apache Maven on Ubuntu 16.04 LTS
The complete guide to installing Apache Maven on Ubuntu 16.04 LTS
Time : 2025-03-17 13:35:27
Edit : Jtti

Apache Maven is a widely used Java project build tool that supports automated project dependency management, compilation, testing, and packaging processes. For developers using Ubuntu 16.04 LTS systems, it is important to know how to install Maven. This article will introduce the two main installation methods in detail, and provide a complete operation process and common problem solutions.

What are the preparations before installation? Since Maven is a Java-based development tool, you first need to ensure that the Java runtime environment is properly configured on your system. Open the terminal (Ctrl+Alt+T) and enter the following command to check whether Java is installed:

java -version

If version information similar to OpenJDK version "1.8.0_191" is displayed, the Java environment is ready. If not, you can install OpenJDK 8 with the following command (this version is recommended for compatibility) :

sudo apt update
sudo apt install openjdk-8-jdk

After the installation, you are advised to set the JAVA_HOME environment variable. Find the JDK installation path by using the following command:

sudo update-alternatives --config java

Make a note of the path like /usr/lib/jvm/java-8-openJDk-amd64 /jre/bin/java, remove the end of the /jre/bin/java, add the path to the environment variable:

echo 'export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"' >> ~/.rc
source ~/.rc

The first installation method is quick installation through APT. The official Ubuntu repository provides pre-compiled Maven packages for users who need quick deployment. Run the following command:

sudo apt update
sudo apt install maven

Verify the version after installation:

mvn -v

The version of Maven installed this way may be older (such as 3.3.9), but the advantage is that dependencies and update maintenance are handled automatically. Suitable for projects that do not have strict version requirements.

The other installation method is to manually install the latest version. Access/Maven website for the latest stable version download link. The following uses version 3.8.8 as an example:

Wget HTTP: / / https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

Unzip the package and move it to the standard directory:

tar -xzvf apache-maven-.tar.gz
sudo mv apache-maven 3.8.8 /opt/

When configuring environment variables, edit the ~/.rc file:

nano ~/.rc

Add at the end of the file:

export MAVEN_HOME=/opt/apache-maven-3.8.8
export PATH=$MAVEN_HOME/bin:$PATH

Save and exit to execute:

source ~/.rc

This method allows you to get the latest features, but requires you to manually handle subsequent upgrades. It is recommended that Maven be installed in the /opt directory to comply with Linux file system specifications.

If you run mvn -v, similar information is displayed:

Apache Maven 3.8.8
Maven home: /opt/apache-maven-3.8.8
Java version: 1.8.0_352, vendor: Oracle Corporation

To improve build efficiency, you are advised to configure the Maven image repository.

Command found no error, check whether the environment variables are configured correctly, paying special attention to whether the PATH contains Maven's bin directory. You can view the current PATH through the echo $PATH command.

If an error Unsupported Maj. minor version occurs in Java version conflicts, the Maven version is incompatible with the Java version. For example, Maven 3.8+ requires Java 8 or later.

If permission is denied during manual installation, use sudo when moving files and ensure that the target directory permissions are:

sudo chown -R $(whoami):$(whoami) /opt/apache-maven-3.8.8

If the dependency download fails, check the network connection and ensure that the image configuration is correct. Temporarily disable firewall testing:

sudo ufw disable

For users of APT installations, periodically perform:

sudo apt update && sudo apt upgrade maven

If you manually install the software, visit the official website periodically to view the latest version. During the upgrade, repeat the steps of downloading and decompressing the software, and update the MAVEN_HOME directory to point to the new version directory. It is recommended to keep the old version directory for at least one iteration period for rollback.

Development environment integration tips such as when you configure Maven in IntelliJ IDEA or Eclipse, the IDE automatically detects which version of the system is installed. To specify a specific version, point to the Maven home directory in IDE Settings. For team projects, it is recommended to specify the Java version via <maven.compiler.source> in pom.xml to ensure build consistency.

With this detailed guide, developers can quickly set up a Maven environment on Ubuntu 16.04 LTS that meets the needs of their project. Whether you choose a stable but slightly older version of the repository or a manual installation for the latest features, the correct configuration can significantly improve the development efficiency of your Java project. Advice periodically review/Maven official documentation for the latest best practices.

JTTI-Defl
JTTI-COCO
JTTI-Selina
JTTI-Ellis
JTTI-Eom