Ubuntu – Ubuntu adding path/Environment variables

Apache2bashcommand lineenvironment-variablesmaven-3

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?

Best Answer

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.