How to permanently set environmental variables PATH and M2_HOME in ubuntu for maven3?
Update: Eliah pointed out to me that if you are not dynamically building your environment variables, you should store them in /etc/environment
. To set M2_HOME
and add the bin
directory to your PATH
, you would modify your /etc/environment
as follows. Make sure that you don't just copy/paste, because your /etc/environment
file might have a different PATH
variable than mine does.
M2_HOME="/home/gaurav/Java/maven3"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/gaurav/Java/maven3/bin"
Alternative (not as recommended) method:
Like Mitch said, you'll need to edit a configuration file to permanently change your PATH. I chose to edit my /etc/profile
configuration file, because it applies system-wide. To edit this file, run sudo nano /etc/profile
Here's the relevant excerpt from my configuration file:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
JAVA_HOME=/usr/lib/jvm/java-6-oracle/
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4
export M2_HOME
M2=$M2_HOME/bin
export M2
PATH=$PATH:$JAVA_HOME
PATH=$PATH:$M2
export PATH
You have to add your PATH to /etc/bash.bashrc as root.
From root do these steps:
sudo nano /etc/bash.bashrc
-
At the end of the file, add the following line:
PATH=/home/computer/application/bin:$PATH
This is just a pseudo address. Change it according to the address that you want and add the :$PATH
after it.
This is for Ubuntu.