How to add a directory to your PATH
A practical comprehensive write-up on updating PATH
by Julia- there's more nuance than I'd known.
Contains a fun and authoritative explaination for ~/.bash
vs ~/.bash_profile
vs ~/.profile
:
Bash has three possible config files:
~/.bashrc
,~/.bash_profile
, and~/.profile
.If youâre not sure which one your system is set up to use, Iâd recommend testing this way:
- add
echo hi there
to your~/.bashrc
- Restart your terminal
- If you see âhi thereâ, that means
~/.bashrc
is being used! Hooray!- Otherwise remove it and try the same thing with
~/.bash_profile
5> You can also try~/.profile
if the first two options donât work.(there are a lot of elaborate flow charts out there that explain how bash decides which config file to use but IMO itâs not worth it and just testing is the fastest way to be sure)
For loading the new config:
Now, an extremely important step: updating your shellâs config wonât take effect if you donât restart it!
Two ways to do this:
- open a new terminal (or terminal tab), and maybe close the old one so you donât get confused
- Run bash to start a new shell (or zsh if youâre using zsh, or fish if youâre using fish)
I was expecting source ~/.<config>
but it's not listed. I was wondering why, and I just realised that the repeated run of commands could fuck things up - running path update twice would create duplicates - and so many other things could go wrong. I had never thought of it before.