TLDR: How to add a directory to your PATH:
- Identify your shell (bash, zsh, fish).
- Find the config file (
~/.bashrc
,~/.zshrc
, or~/.config/fish/config.fish
). - Determine the directory to add, usually where a program is installed.
- Edit your config file:
- For bash:
export PATH=$PATH:/path/to/dir
- For zsh:
path=($path /path/to/dir)
- For fish:
set PATH $PATH /path/to/dir
- For bash:
- Restart your terminal or run a new instance of your shell to apply changes.
Common issues:
– Wrong program runs: Add directory to the front of PATH.
– Program not run from the shell: Update PATH differently for non-shell execution.
– Duplicate PATH entries: Check for existing entries before adding.
– History loss after updating: Use source ~/.bashrc
instead of starting a new shell.
For fish shell: fish_add_path
can add directories but may complicate future removals.
https://jvns.ca/blog/2025/02/13/how-to-add-a-directory-to-your-path/