How to Add a Directory to Your PATH

TLDR: How to add a directory to your PATH:

  1. Identify your shell (bash, zsh, fish).
  2. Find the config file (~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish).
  3. Determine the directory to add, usually where a program is installed.
  4. 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
  5. 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/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top