Install Maven

Maven needs a JDK first (it runs on Java). Then install Maven itself, or β€” better β€” use the wrapper that most projects ship with.

Install & verify

bash
# macOS (Homebrew)
brew install maven
# then check:
mvn -version

mvn -version prints the Maven version *and* the Java version it's using β€” confirm both are what you expect.

JAVA_HOME

Maven uses JAVA_HOME to find the JDK. If mvn -version shows the wrong Java, set it.

bash
export JAVA_HOME=/path/to/jdk-21

The Maven Wrapper (preferred)

Most projects include mvnw/mvnw.cmd β€” the Maven Wrapper. It downloads and runs the exact Maven version the project needs, so everyone (and CI) builds identically, with no global install.

bash
./mvnw -version      # macOS/Linux
mvnw.cmd -version    # Windows

The .m2 folder

Maven stores its local cache and optional settings in a .m2 folder in your home directory: ~/.m2/repository (downloaded libraries) and ~/.m2/settings.xml (optional config, covered later).

Tip: Prefer ./mvnw over a globally installed mvn in real projects β€” it guarantees the whole team uses the same Maven version.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
Install Maven β€” Maven | Full Stack Learning Simplified