Extend fish PATH
$PATH
is an environment variable containing the directories that fish searches for commands. Unlike other shells, $PATH
is a list, not a colon-delimited string.
To prepend /usr/local/bin
and /usr/sbin
to $PATH
, you can write:
set PATH /usr/local/bin /usr/sbin $PATH
To remove /usr/local/bin
from $PATH
, you can write:
set PATH (string match -v /usr/local/bin $PATH)
For compatibility with other shells and external commands, $PATH
is a path variable, and so will be joined with colons (not spaces) when you quote it:
echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/bin
and it will be exported like that, and when fish starts it splits the $PATH
it receives into a list on colon.
You can do so directly in config.fish
, like you might do in other shells with .profile
. See this example:
A faster way is to modify the $fish_user_paths
universal variable, which is automatically prepended to $PATH
. For example, to permanently add /usr/local/bin
to your $PATH
, you could write:
set -U fish_user_paths /usr/local/bin $fish_user_paths
The advantage is that you don’t have to go mucking around in files: just run this once at the command line, and it will affect the current session and all future instances too. (Note: you should NOT add this line to config.fish
. If you do, the variable will get longer each time you run fish!)
Resources
- https://github.com/fish-shell/fish-shell
- https://fishshell.com/docs/current/tutorial.html#tut-lists
- https://fishshell.com/docs/current/index.html#variables-path
- https://fishshell.com/docs/current/tutorial.html#tut-universal