Monday, 20 July 2015

Apache Maven : Apache Maven Installation (Linux OS)

🚀 Want to Master Linux, Java & DevOps Build Tools?

Subscribe to Ram N Java for beginner-friendly programming tutorials, server setups, and automated build guides!

🔔 Subscribe to YouTube Channel

Maven Installation on Linux: Your Ultimate Step-by-Step Guide

Apache Maven is an essential open-source build automation and dependency management tool used across enterprise Java development and modern CI/CD pipelines. Installing Maven on a Linux distribution (such as Ubuntu, Debian, CentOS, Red Hat, or Amazon Linux EC2) enables you to compile code, package WAR and JAR artifacts, and manage project dependencies directly from the terminal.

1. Prerequisites: Verify Java (JDK) on Linux

Because Maven itself is written in Java and compiles Java code, having a properly configured Java Development Kit (JDK) is mandatory:

  • Check JDK Installation: Open your Linux terminal and execute:
    java -version
  • Verify JAVA_HOME: Ensure that your JAVA_HOME environment variable is set and accessible:
    echo $JAVA_HOME
  • If Java is not installed or the variable returns empty, install OpenJDK (version 8, 11, 17, or 21) before proceeding with the Maven setup.

2. Downloading the Apache Maven Archive

To obtain the latest stable release of Apache Maven:

  • Navigate to your temporary or installation directory (for instance, /tmp or /opt):
    cd /opt
  • Download the binary tarball archive (tar.gz) from Apache mirrors using wget:
    sudo wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
  • Extract the downloaded archive using the tar command:
    sudo tar -xvzf apache-maven-3.9.9-bin.tar.gz
  • (Optional) Create a symbolic link for convenient future version upgrades:
    sudo ln -s /opt/apache-maven-3.9.9 /opt/maven

3. Configuring Environment Variables (M2_HOME & PATH)

To execute mvn commands system-wide from any terminal location, configure your profile environment settings:

  • Create or edit a Maven environment profile script in /etc/profile.d/maven.sh:
    sudo nano /etc/profile.d/maven.sh
  • Add the following export statements into the file:
    export M2_HOME=/opt/maven
    export MAVEN_HOME=/opt/maven
    export PATH=${M2_HOME}/bin:${PATH}
  • Save the file and grant it executable permissions:
    sudo chmod +x /etc/profile.d/maven.sh
  • Reload the environment variables in your current session:
    source /etc/profile.d/maven.sh

4. Testing and Verifying Maven Installation

Validate that Maven is properly recognized by the Linux shell:

  • Run the version command:
    mvn -version
  • Expected Output: The terminal will print the installed Apache Maven version, Maven home directory, Java version, and Linux OS architecture details. Once visible, Maven is fully prepared to build your Java projects.

📺 Explore More Related Tutorials

Expand your Linux server administration and Java environment setup knowledge with these related tutorials from our channel:


Click here to watch on YouTube:
https://www.youtube.com/watch?v=zpOX8F_vW1k&list=UUhwKlOVR041tngjerWxVccw

Click here to download Apache Maven:
https://maven.apache.org/download.cgi


Click here to watch in Youtube :
https://www.youtube.com/watch?v=zpOX8F_vW1k&list=UUhwKlOVR041tngjerWxVccw

Click here to download Apache Maven :

http://maven.apache.org/

http://maven.apache.org/download.cgi

http://maven.apache.org/install.html


Linux Commands:
#wget http://apache.arvixe.com/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz

#tar xvf apache-maven-3.3.3-bin.tar.gz

#mvn –version

Maven Path Setup:
export M2_HOME=/opt/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Click the below Image to Enlarge
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Tutorials