lennxa

How to add a directory to your PATH

Source | #tech, #bash

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:

  1. add echo hi there to your ~/.bashrc
  2. Restart your terminal
  3. If you see “hi there”, that means ~/.bashrc is being used! Hooray!
  4. 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:

  1. open a new terminal (or terminal tab), and maybe close the old one so you don’t get confused
  2. 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.

#bash #links #tech