Set Maven Home on Ubuntu
Use this when Maven is installed manually (tar/zip) and not via apt.
1. Find Maven installation directory
Example:
/data/dev/tools/apache-maven-3.9.9
2. Configure environment variables
Edit profile file:
sudo nano /etc/profile
Add at the end:
M2_HOME=/data/dev/tools/apache-maven-3.9.9
PATH=$PATH:$M2_HOME/bin
export M2_HOME
export PATH
Load changes:
source /etc/profile
3. Verify
echo $M2_HOME
mvn -v
Expected output includes Maven home path and Java version.
Optional: user-level config
If you do not want system-wide changes, add the same exports to ~/.bashrc or ~/.zshrc.
Key Takeaways
- Keep configuration explicit and environment-specific.
- Verify setup with version and env checks immediately after changes.
- Automate these steps in shell profiles or project docs to avoid drift.