Modifying PATH with fish shell

Paymahn Moghadasian picture Paymahn Moghadasian · Oct 6, 2014 · Viewed 56.2k times · Source

I'm currently playing around with the fish shell and I'm having some trouble wrapping my head around how the PATH variable is set. For what it's worth, I'm also using oh-my-fish.

If I echo my current path I get:

➜ fish echo $PATH
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /opt/X11/bin /usr/texbin /Users/myname/.opam/system/bin

Looking at ~/.config/fish/config.fish I see the following line

set PATH /usr/local/bin $PATH /Users/myname/.opam/system/bin

My question is (and this phrasing will probably reflect my lack of knowledge on the subject): prior to config.fish being processed, where is the PATH variable set? ie: where do all of the paths between /usr/local/bin and /Users/myname/.opam/system/bin come from?

Answer

Kasper picture Kasper · Dec 21, 2015

As stated in the official fish tutorial, you can modify the $fish_user_paths universal variable.

Run the following once from the command-line:

set -U fish_user_paths /usr/local/bin $fish_user_paths

This will prepend /usr/local/bin permanently to your path, and will affect the current session and all future instances too because the -U argument will make the variable universal.

From the fish documentation:

... (Note: you should NOT add this line to config.fish. If you do, the variable will get longer each time you run fish!)

fish_user_paths, a list of directories that are prepended to PATH. This can be a universal variable.