I'm trying to add a directory to my path so it will always be in my Linux path. I've tried:
export PATH=$PATH:/path/to/dir
This works, however each time I exit the terminal and start a new terminal instance, this path is lost, and I need to run the export command again.
How can I do it so this will be set permanently?
Put the
export
declaration in~/.bashrc
. My .bashrc contains this:My answer is in reference to the setting-up of
go-lang
onUbuntu linux/amd64
.I have faced the same trouble of setting the path of environment variables (GOPATH
andGOBIN
), losing it on terminal exit and rebuilding it using thesource <file_name>
every time.The mistake was to put the path (GOPATH
andGOBIN
) in~/.bash_profile
folder. After wasting a few good hours, I found that the solution was to putGOPATH
andGOBIN
in~/.bash_rc
file in the manner:and doing so, the go installation worked fine and there were no path losses.
EDIT 1: The reason with which this issue can be related is that settings for non-login shells like your ubuntu terminal or gnome-terminal where we run the go code are taken from
~./bash_rc
file and the settings for login shells are taken from~/.bash_profile
file, and from~/.profile
file if~/.bash_profile
file is unreachable.You need to add it to your
~/.profile
or~/.bashrc
file.Depending on what you're doing, you also may want to symlink to binaries:
Note that this will not automatically update your path for the remainder of the session. To do this, you should run:
I think the most elegant way is:
1.add this in ~/.bashrc file Run this command
add your path inside it
2.source ~/.bashrc
(Ubuntu)
You can add that line to your console config file (e.g. .bashrc) , or to .profile
1.modify "/etc/profile" file.
Press "i" key to enter editing status and move cursor to the end of the file,Additional entries:
Press "Esc" key exit edit status,':wq' save the file.
2.Make configuration effective
Explain: profile file works for all users,if you want to be valid only for the active user, set the ".bashrc" file