I've found myself with the need to add a new path permanently in all terminal sessions on my Mac. Specifically I want to add the contents of my $GOPATH/bin to my $PATH.
So far I think my options are to either:
- Add it to my $HOME/.bash_profile file using export syntax.
- Create a file containing the path to add in the /etc/paths.d directory.
I've settled on option 2, because I like the idea of just adding files with one line in whenever I want a new path added permanently.
I have tried adding in a file /etc/profile.d/gopath
containing ~/code/go/bin
. This works. However, what I'd like to do is evaluate the environment variable, $GOPATH/bin
such that if I decide to change my $GOPATH I only have to change the variable. However, that just adds the literal words "$GOPATH/bin" to my path, it doesn't actually add the directory to my path. The $GOPATH bash environment variable is currently set in my ~/.bashrc
file.
Some questions:
- Why doesn't the $ syntax evaluate in the $PATH or setting of $PATH? Is that not bash?
- What comes first, the inclusion of
~/.bashrc
,~/.bash_profile
or/etc/profile.d
? It is reasonable of me to think that the environment variable would be there when setting the $PATH? - How can I have this environment variable be evaluated and substituted if it is feasible?
Thanks for your help. All my searches don't seem to come up with the above answers.