How to add a path to Fish Shell
By Flavio Copes
Learn how to add a folder to your PATH in the Fish shell using the fish_add_path command, so you can run commands stored in that directory from anywhere.
To add a folder to your PATH in Fish, use the fish_add_path command. One line, and the change persists across sessions.
I was looking for a fast way to add a path to my Fish Shell, so I could execute commands into that folder.
Here’s how to do that in Fish Shell:
fish_add_path "/Users/flavio/bin"
That’s the whole setup. No config file to edit, no shell restart needed.
What fish_add_path actually does
The command stores the folder in fish_user_paths, a universal variable. Universal variables survive restarts and sync across every open fish session, so the new PATH entry works immediately, in all your terminal tabs.
Check it worked:
echo $PATH
You’ll see /Users/flavio/bin near the front of the list. By default the folder is prepended, so commands in it take precedence over commands with the same name elsewhere. If you want it at the end instead, pass -a:
fish_add_path -a "/Users/flavio/bin"
The command is also idempotent. Run it ten times and the folder shows up once. No duplicate entries.
The old way, and why I avoid it
Before fish_add_path existed, the usual advice was to edit ~/.config/fish/config.fish and prepend to PATH manually:
set -gx PATH /Users/flavio/bin $PATH
It works, but every new shell runs config.fish again and prepends the folder again. Nested fish sessions end up with the same entry repeated in the PATH. That’s the pitfall fish_add_path fixes, since it checks for the entry before adding it.
Note that fish_add_path needs fish 3.2 or newer. Run fish --version if you’re not sure what you have.
How to remove the path later
Since the entry lives in fish_user_paths, you can inspect that variable directly:
echo $fish_user_paths
To remove an entry, write back the list without it:
set -U fish_user_paths (string match -v /Users/flavio/bin $fish_user_paths)
string match -v filters the folder out, and set -U saves the filtered list back to the universal variable.
Related posts about cli: