I am trying to install apache maven 3 in Ubuntu 12.04 lts. What I did was open the terminal then I typed the following commands

  • export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.5 [Then pressed Enter]
  • export M2=$M2_HOME/bin [Then pressed Enter]
  • export PATH=$M2:$PATH [Then pressed Enter]

After that I typed

mvn --version

and it displayed all the necessary information but after closing the terminal, again I typed the command mvn --version

then it said that 'mvn' is not recognized

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

is there a way to permanently add a PATH variable in Ubuntu?


Add those export lines to your ~/.profile file.

If you want it to apply to all users on the system, put it in /etc/profile instead;

sudoedit /etc/profile

Once you've edited either, you'll see the effect next time you log in.

See also http://mywiki.wooledge.org/DotFiles

On a side-note, if you instead install maven via the software center or apt-get, you won't need to do any of the above.

  • I tried the apt-get but it is the old version. I am using 12.04 lts. anyways where would I place it here? I already tried sudoedit /etc/profile but i have no idea where to place it here – user962206 Jun 19 '13 at 9:15
  • @user962206, You can put them at the very end. – geirha Jun 19 '13 at 13:28

This might help to add the environment variable permanently. Use the following command, for editing the file:

sudo gedit /etc/environment

Then use this command, to source it:

source /etc/environment

Reference - Installing Maven 3 on Ubuntu 10.04 LTS Server

  • "$source" is no command – phil294 Oct 7 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.