Fullstack > Tools > 📦 Maven
Apache Maven
Apache Maven is a powerful build automation tool used primarily for Java projects. It helps manage dependencies, build processes, and project structures efficiently. This guide will help you install Maven on your system.
Step 1: Download Maven
- Go to the official Apache Maven Download page.
- Download the latest binary zip file for your operating system (Windows, macOS, or Linux).
- Extract the downloaded file to a directory of your choice (e.g.,
C:\Program Files\Apache\Mavenon Windows or/opt/mavenon Linux/macOS).
Step 2: Set Up Environment Variables
On Windows:
- Open System Properties > Advanced > Environment Variables.
- Add a new system variable:
- Variable name:
MAVEN_HOME - Variable value: Path to the extracted Maven directory (e.g.,
C:\Program Files\Apache\Maven)
- Variable name:
- Edit the
Pathvariable and add%MAVEN_HOME%\bin.
On macOS and Linux:
- Open the terminal and edit your shell profile file:
nano ~/.bashrc # or ~/.zshrc - Add the following lines:
export MAVEN_HOME=/opt/maven export PATH=$MAVEN_HOME/bin:$PATH - Apply changes:
source ~/.bashrc
Step 3: Verify Installation
To check if Maven is installed correctly, run the following command:
mvn -version
If installed successfully, you should see output similar to:
Apache Maven 3.x.x (latest version)
Maven home: /path/to/maven
Java version: 1.8.0_xxx, vendor: Oracle Corporation
Step 4: Run a Sample Maven Project
- Open a terminal or command prompt and create a new Maven project:
mvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false - Navigate into the project directory:
cd my-app - Build the project:
mvn package - Run the application:
java -cp target/my-app-1.0-SNAPSHOT.jar com.example.App
Conclusion
You have successfully installed Maven on your system! You can now use it to manage dependencies and build Java projects efficiently.