Ever wondered what happens behind the scenes when you run a Maven command? It's like a well-oiled factory. Maven follows a specific set of rules and steps to turn your source code into a finished product, like a JAR or WAR file.
The Three Repositories
Maven doesn't just look for files on your computer. it uses a clever system of repositories to find exactly what your project needs:
Local Repository: This is a folder on your own machine where Maven stores everything it has downloaded before.
Central Repository: If Maven can't find a library locally, it goes to the "Central" hub on the internet to fetch it.
Remote Repository: Sometimes companies have their own private "vaults" for custom code that Maven can also access.
The Build Lifecycle
When you tell Maven to "build," it goes through a lifecycle. It starts by cleaning up old files, then compiles your code, runs tests to make sure everything works, and finally packages it up. Because this process is standardized, any developer can pick up your project and build it with a single command!
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:
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:
Maven Installation on Windows Operating System: The Easy Step-by-Step Guide
Apache Maven is the industry standard build automation and dependency management tool for Java applications. From downloading required libraries automatically via central repositories to running automated tests and packaging JAR or WAR files, Maven simplifies the complete project lifecycle. Setting it up on Windows takes only a few minutes when following the proper configuration steps.
1. Prerequisites Before Installing Maven
Before configuring Maven, ensure your system meets the basic requirements:
Java Development Kit (JDK): Maven requires JDK to compile Java source code. Make sure JDK (Java 8 or higher) is installed.
JAVA_HOME Environment Variable: Ensure your JAVA_HOME system environment variable points directly to your JDK directory (e.g., C:\Program Files\Java\jdk-17).
Verify Java: Open Command Prompt and run java -version and echo %JAVA_HOME% to confirm Java is ready.
2. Downloading and Extracting Apache Maven
Maven does not require a traditional installer; it runs directly from its binary directory:
Under the Files section, download the Binary zip archive (e.g., apache-maven-x.x.x-bin.zip).
Extract the downloaded zip archive to a clean, permanent directory such as C:\apache-maven or C:\Program Files\apache-maven.
3. Setting Up MAVEN_HOME and PATH Environment Variables
To allow the Windows Command Prompt to recognize Maven commands from any directory:
Press Win + S, search for Environment Variables, and open Edit the system environment variables.
Click the Environment Variables... button at the bottom right.
Under System variables, click New:
Variable name:MAVEN_HOME (or M2_HOME)
Variable value: Path to your extracted Maven folder (e.g., C:\apache-maven-3.9.x)
Under System variables, locate the Path variable and click Edit.
Click New and add: %MAVEN_HOME%\bin (or the direct path like C:\apache-maven-3.9.x\bin).
Click OK on all dialog boxes to save the configuration.
4. Verifying the Maven Installation
Test that the command-line interface communicates with Maven:
Open a fresh Command Prompt window (to reload system environment variables).
Run the command: mvn -version (or mvn -v).
You should see details showing the Apache Maven version, Maven home directory, Java version, and OS details. If displayed, Maven is fully configured and ready to use!