How to Install Maven on Windows, Linux and macOS - Quiz
Total: 6 questions
1. What does installing Maven mean, and what do you need before you install it?
What does installing Maven mean, and what do you need before you install it?
Installing Maven means downloading the Apache Maven distribution (an archive of ready-to-run files), unpacking it and adding its bin directory to the PATH environment variable so that the mvn command works from any folder. There is no classic installer: on Windows, installation comes down to unpacking the archive and setting environment variables, while on Linux and macOS a package manager (apt, dnf, brew) or SDKMAN is usually more convenient.
Before installing you need a JDK, not just a JRE: Maven 3.10.0 (the recommended version) and the previous 3.9.x line run on Java 8 or newer, while Maven 4 (still in preview) requires Java 17 or newer. Maven finds Java through the JAVA_HOME variable (the JDK root) or, if it is not set, through the java command on the PATH. Check the JDK with java -version and javac -version: if javac is not found, you have only a JRE or the JDK is not on the PATH.
A manual installation does not require administrator rights. If you only work in IntelliJ IDEA or Eclipse, Maven is already bundled with the IDE; a separate installation is needed to run mvn in a terminal, in scripts and on a CI server.
2. What are the ways to install Maven, and which one should you choose?
What are the ways to install Maven, and which one should you choose?
- Archive from maven.apache.org - unpack it and add
bintoPATH. Works on any OS, gives you the latest version, needs no administrator rights; variables and upgrades are manual. - Windows: Chocolatey, Scoop, winget -
choco install maven(administrator console),scoop install maven(no administrator rights); check whether winget has Maven and its exact ID withwinget search maven.Pathis configured automatically, but the JDK must be installed beforehand. - Linux: apt, dnf, apk -
sudo apt install maven,sudo dnf install maven,apk add maven. One command, but the repository version may lag behind: Ubuntu 22.04 installs 3.6.3, Ubuntu 24.04 and Debian 12 install 3.8.7. - macOS: Homebrew -
brew install maven, upgrade withbrew upgrade maven. The formula installs its ownopenjdkand, withoutJAVA_HOME, runs Maven on it, so the Java version inmvn -versionmay differ fromjava -version. - SDKMAN (Linux, macOS, WSL) -
sdk install maven; handy when you need several Maven or JDK versions (sdk use,sdk default). Does not work on plain Windows without WSL or Git Bash.
For a single project you may not need a global installation at all if the project ships with the Maven Wrapper (mvnw).
3. Where do you download Maven, which file do you pick, and how do you verify the downloaded archive?
Where do you download Maven, which file do you pick, and how do you verify the downloaded archive?
Download Maven from the official Apache site - maven.apache.org/download.cgi, the "Files" section. On Windows choose the Binary zip archive (apache-maven-3.10.0-bin.zip), on Linux and macOS the Binary tar.gz archive (apache-maven-3.10.0-bin.tar.gz). Archives with src in the name contain source code and are not meant for installation.
Both binary archives contain exactly the same files: Maven is written in Java and does not depend on the OS, only the packaging format differs. This is also the "portable" Maven: you can copy the unpacked folder to another directory or a USB stick, and bin\mvn -version runs from there without any installation.
The dlcdn.apache.org mirror keeps only current versions; older ones are in archive.apache.org/dist/maven/maven-3/.
Checksum: next to each archive there is a .sha512 file. Compute the hash and compare - the strings must match exactly:
Get-FileHash .\apache-maven-3.10.0-bin.zip -Algorithm SHA512 # Windows (PowerShell)
sha512sum apache-maven-3.10.0-bin.tar.gz # Linux
shasum -a 512 apache-maven-3.10.0-bin.tar.gz # macOS
PowerShell prints the hash in uppercase, while the .sha512 file uses lowercase - that is fine.
4. How do you install Maven on Windows 10 and 11, and do you need the M2_HOME variable?
How do you install Maven on Windows 10 and 11, and do you need the M2_HOME variable?
- Unzip the archive into a folder without spaces, for example
C:\dev: you getC:\dev\apache-maven-3.10.0with thebin,boot,confandlibsubfolders. - Open the Environment Variables dialog: Win+R →
sysdm.cpl→ "Advanced" → "Environment Variables". User variables need no administrator rights. - Create
JAVA_HOMEwith the JDK root as the value, without\binat the end. - Add
C:\dev\apache-maven-3.10.0\bintoPath. - Close every open terminal, open a new window and run
mvn -version.
M2_HOME is not needed: Maven scripts stopped reading it in version 3.5.0. Only the bin directory on PATH and a JDK are required. You can create MAVEN_HOME for convenience (and put %MAVEN_HOME%\bin into Path), but Maven itself does not require it.
Do not add Maven to PATH with setx: it truncates the value to 1024 characters. Instead of the Environment Variables dialog you can use PowerShell - [Environment]::SetEnvironmentVariable(..., "User").
5. How do you check that Maven is installed correctly, and what should you look at in the mvn -version output?
How do you check that Maven is installed correctly, and what should you look at in the mvn -version output?
Run mvn -version (or mvn -v) in a new terminal. It prints the Maven version, the installation directory and the JDK Maven runs on:
- Apache Maven - the version that actually runs. If it is older than expected, another installation comes earlier in
PATH: check withwhere mvn(Windows) orwhich mvn(Linux, macOS). - Maven home - where Maven runs from (after
apt installit is/usr/share/maven). - Java version / runtime - the JDK Maven runs on; its
javaccompiles your project, even ifjava -versionreports a different version. If this is a JRE, the build fails withNo compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Typing mvn with no arguments is not an installation error: Maven works but reports No goals have been specified for this build. And mvn package in a folder without pom.xml ends with there is no POM in this directory - change to the project root first.
6. What is the difference between installing Maven and the mvn install command?
What is the difference between installing Maven and the mvn install command?
"Installing Maven" means putting the tool itself on your computer: download the distribution, unpack it, add bin to PATH (or use a package manager) and check mvn -version.
The mvn install command has nothing to do with that: it is a build lifecycle phase that compiles and tests your project, packages it into a jar and copies the result into the local repository ~/.m2/repository so that your other projects can use it as a dependency. The output shows lines like [INFO] Installing ... to ~/.m2/repository/... and BUILD SUCCESS.
To just build a jar, mvn package is enough - the file appears in the target directory.