Install Apache Maven on Debian to build Java projects and manage their dependencies from the command line. This guide shows how to install Maven from Debian’s package repository, check that it works, and use an optional manual installation when you need a different version. You’ll need a Debian account with sudo access and a Java Development Kit (JDK).
What You’ll Need
- A Debian system with an internet connection.
- A user account that can run commands with
sudo, or root access. - A JDK. Maven needs Java to run; install a JDK rather than only a Java runtime.
- A terminal window.
Step-by-Step
- Open a terminal and refresh the package list. Run
sudo apt update. This updates the local list of available packages; it does not upgrade the system by itself. If you are already logged in as root, omitsudo. - Install a JDK. On Debian releases that provide the default JDK package, run
sudo apt install default-jdk. Debian selects the default version for that release. If your project requires a specific Java release, install the corresponding JDK package available for your Debian version instead. Confirm Java is available withjava -version, then check the compiler withjavac -version. Both commands should print version information. - Install Maven from Debian’s repository. Run
sudo apt install mavenand confirm the package manager’s prompt. APT installs Maven and its required dependencies, and sets up the executable for normal command-line use. This is the simplest method for most Debian users. The Maven version in the repository depends on your Debian release, so it may not be the newest upstream release. - Check the installation. Run
mvn -version. The output should include an Apache Maven version, a Java version, and the Java home directory. Check that the Java version is one your project supports. If you see “command not found,” continue to Troubleshooting below. - Run Maven in a project directory. Change to a Java project that contains a
pom.xmlfile, then runmvn testor the build command specified by that project. Maven may download plugins and dependencies the first time; this requires network access. For a quick independent check, create an empty directory and runmvn archetype:generateonly if you want to create a sample project. This command can prompt you for options and is not required to verify installation. - Use a newer Maven manually only if needed. If the repository version does not meet a project requirement, get the binary archive for the required Maven release from the Apache Maven project’s official download page. Verify the archive’s published checksum or signature before using it. Extract it to a stable location, such as
/opt/maven, and point your PATH to itsbindirectory. For example, if you extracted the files into/opt/apache-maven-3.x.y, addexport PATH="/opt/apache-maven-3.x.y/bin:$PATH"to your shell’s startup file, then open a new terminal and runmvn -version. Replace the example directory with the real extracted path. Avoid replacing Debian-managed files in/usr/bin.
Common Mistakes
- Installing Java but not the JDK: Maven can start with a runtime, but Java builds commonly need compiler tools. Install a JDK and verify
javac -version. - Assuming APT provides the latest Maven: Debian prioritizes packages maintained for each release. Check
mvn -versionagainst the version required by your project before choosing a manual installation. - Using a mismatched Java version: A project may need a particular JDK even if Maven itself starts successfully. Read the project’s build instructions and use a compatible JDK.
- Editing the wrong PATH file: Bash, Zsh, and other shells can read different startup files, and interactive and login sessions may behave differently. Confirm your shell with
echo "$SHELL"and start a fresh terminal after editing its configuration. - Downloading an unverified archive: Use the official project download source and verify the provided checksum or signature. Do not run an archive from an untrusted mirror.
Tips
- Prefer
sudo apt install mavenfor a straightforward installation. APT handles package updates and removal cleanly. - Use
mvn -versionwhenever you need to confirm which Maven and Java installations your shell is using. - Keep project-specific Java requirements in mind. Maven’s ability to run does not guarantee that a particular project can compile with the selected JDK.
- If you install Maven manually, keep its directory separate from Debian-managed software. Update the PATH entry when changing releases, and remove obsolete entries to avoid ambiguity.
- For repeatable builds, follow the project’s own instructions. Some projects include a Maven Wrapper, which selects or downloads the Maven version configured by the project; run it as
./mvnwwhere provided.
Troubleshooting
mvn: command not found: For an APT installation, checkdpkg -l mavenand trysudo apt install mavenagain. For a manual install, confirm the extractedbindirectory is in PATH, then open a new terminal. Usecommand -v mvnto see which executable your shell finds.- Maven reports that Java is missing: Run
java -versionand install a JDK if needed. If Java is installed but not detected, inspectJAVA_HOMEwithecho "$JAVA_HOME". It should refer to the JDK directory, not itsbinsubdirectory. Debian’s alternatives system usually configures Java for package installations; avoid setting JAVA_HOME unless your project or environment needs it. - The wrong Maven version appears: Run
command -v mvnto locate the executable and inspect PATH order. APT’s executable may be found before a manual installation, or an older manual PATH entry may take precedence. Adjust the PATH so the intended installation comes first. - Dependency downloads fail: Check internet access, proxy settings, and any network restrictions. Retry after the connection is available. Do not delete Maven’s local repository by default; it is usually under
~/.m2/repository, and removing it forces dependencies to download again. - APT cannot locate the package: Run
sudo apt updateand check that your Debian package sources are configured for your release. If repository access remains unavailable, consult your system administrator rather than adding an untrusted repository.
Frequently Asked Questions
Does Maven require Java?
Yes. Maven runs on Java, and Java projects generally need a JDK for compilation. Install a JDK compatible with your project.
What is the quickest way to install Maven on Debian?
Install a JDK, then run sudo apt update and sudo apt install maven. Check the result with mvn -version.
Will APT install the latest Maven release?
Not necessarily. APT installs the version packaged for your Debian release. Use a verified upstream archive if you specifically require a newer version.
How do I uninstall Maven installed with APT?
Run sudo apt remove maven. To remove package configuration files as well, use sudo apt purge maven. This does not necessarily remove every dependency or your files under ~/.m2.
Can I install Maven without root access?
Yes, if you can download and verify the archive and extract it into a directory you own. Add that installation’s bin directory to your user PATH. You will still need an appropriate JDK.
What is the Maven Wrapper?
It is a project-provided script that runs a configured Maven version. If the project includes it, use ./mvnw (or mvnw.cmd on Windows) instead of relying on a system-wide Maven version.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Philips DST7060/20 7000 Series Iron: Specs & Fit
- Coal Fueled Jet Aircraft: Could It Work?675 L
- Remote Desktop on Raspberry Pi: How to Enable It
- Word Select Last Line in Paragraph?
- Google Assistant IFTTT Recipes: 7 Useful Automations
- OLED TVs in Dark Rooms: Why They Look Better and When They Don’t