I have downloaded the latest apache-maven3.zip file and extracted it to the folder:
/home/gaurav/Java/maven3
.
I don't know how to set the environmental variables for maven – such as PATH and M2_HOME.
I tried below things:
export M2_HOME=/home/gaurav/Java/maven3
export PATH= /home/gaurav/Java/maven3/bin:${PATH}
After setting that, I ran mvn --version
and it is running correctly.
But when next time I start my machine, and type $M2_HOME
, its not showing me the details of the path variables, neither mvn --version
is getting executed.
Please help me to resolve this problem of permanently setting environment variables in Ubuntu.
Best Answer
Update: Eliah pointed out to me that if you are not dynamically building your environment variables, you should store them in
/etc/environment
. To setM2_HOME
and add thebin
directory to yourPATH
, 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 differentPATH
variable than mine does.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, runsudo nano /etc/profile
Here's the relevant excerpt from my configuration file: