4
votes

I tried to install Maven to Ubuntu but something goes wrong.

I downloaded Maven and untarred it to folder /usr/local/apache-maven/apache-maven-3.0.4. Then I added these rows to /etc/environment.

export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4

export M2=$M2_HOME/bin

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$JAVA_HOME:$JRE_HOME:$M2:$PATH"

But when I try to verify my installation by mvn --version I get this message

'The program 'mvn' can be found in the following packages: * maven * maven2 Try: sudo apt-get install '

SOLVED. Sorry that if forget to reply to this. I added export rows to ~/.bashrc and after that it started to work.

3
Did you open a new terminal window after updating /etc/environment ? - Wim Deblauwe

3 Answers

2
votes

Had the same issue, this is how i solved it.

1- Install Maven2 from Synaptic rather than downloading it from the website.

2- gedit ~/.bashrc and check if you have M2_HOME and M2 env variables defined if so DELETE them, delete them from PATH too, if there is a reference to them.

3- Reload bash and trymvn --version again.

1
votes

please check if mvn in $M2 is executable. if not you need to make it executable by running

chmod +x mvn
0
votes

Since Ubuntu 16.04.3 LTS release, Maven can be installed from the official repository by running following commands:

  • sudo apt update
  • sudo apt install maven

Each time you hit sudo apt update it will update to the latest version.

Update: After installation is complete, run in the terminal mvn -v to see if package was installed.