How to save environment variable from Terminal?
11,380
Add that line to ~/.bashrc
, or the appropriate configuration file for your shell.
Author by
David
Updated on September 18, 2022Comments
-
David over 1 year
I am trying to save the PATH environment variable from the Terminal running on a Ubuntu system.
I typed in the following however it does not get saved.
export PATH=/home/david/Komodo-Edit-6/bin/:$PATH
Any suggestions on how I can fix this? Thank you.
-
David about 13 yearsTo you mean this
export PATH=/home/david/Komodo-Edit-6/bin/:$PATH ~/.bashrc
, because it doesn't work. I am using the bash shell. -
HikeMike about 13 years@David No. I mean to edit the file
~/.bashrc
and add theexport
statement to its contents. -
David about 13 yearsThanks, I eventually edited
/root/.bash_profile
and it now works. -
user1686 about 13 years@Daniel: In the specific case of appending/prepending to
$PATH
environment variable, the profile file is even better, because 1) the new value is exported to other processes anyway, and 2) if it was in bashrc, then you could end up with the same directory 3 or 4 times. -
HikeMike about 13 years@grawity I read that
.profile
is ignored if.bashrc
or.bash_profile
exist and don't load it explicitly. Is this wrong? -
user1686 about 13 years@Daniel: In login shell mode, bash looks for
.bash_profile
,.bash_login
,.profile
(in that order) and only uses the first one found. (See manual page of bash(1), section "INVOCATION".) In my previous comment, by saying "profile file" I was referring to all three files. -
user1686 about 13 years@Daniel: For completeness: In non-login mode, bash only looks for
.bashrc
. -
HikeMike about 13 years@grawity That's what I read too (although I didn't really understand your comment, as should be obvious), and thought I remembered
.bash_profile
usually loading.bashrc
on Linux, so it seemed the best choice.