mvn command not found - Ubuntu
How to Install mvn Command on Ubuntu
If you are using Ubuntu and trying to run the mvn command but encountering a “command not found” error, it means that Maven is not installed on your system. Maven is a build automation tool used primarily for Java projects to manage project dependencies and build processes.
Here’s how you can install Maven on your Ubuntu system:
- Update Package Index:
sudo apt update
- Install Maven:
sudo apt install maven
- Verify Installation: You can verify the installation by checking the Maven version:
mvn -version
If you encounter any issues during installation, such as compatibility problems with the apt package manager, you can try the following alternative method:
- Download Maven:
wget https://downloads.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
- Extract the Archive:
sudo tar -xf apache-maven-3.8.5-bin.tar.gz -C /opt
- Set Environment Variables:
Add the following lines to your
~/.bashrcfile to set Maven environment variables:
export M2_HOME=/opt/apache-maven-3.8.5
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
- Reload the Bash Profile:
source ~/.bashrc
- Verify Installation: Check the Maven version to ensure it was installed correctly:
mvn -version
By following these steps, you should be able to successfully install the mvn command on your Ubuntu system and start using Maven for your Java projects.
Remember to adjust the version numbers in the commands above to match the latest version of Maven available at the time of installation.
Conclusion
Installing the mvn command on Ubuntu is essential for Java developers who rely on Maven for managing project dependencies and building applications. By following the installation steps outlined in this tutorial, you can easily set up Maven on your Ubuntu system and streamline your development workflow.