Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying PATH with fish shell [closed]

People also ask

How do you set the path on a fish shell?

Use a universal fish_user_paths - this is the default if it doesn't already exist. Manipulate PATH directly. Move already-existing components to the place they would be added - by default they would be left in place and not added again. Print the set command used.

How do you remove path from fish shell?

At least by default, PATH is a global variable, which means it is per-session. That means to change something from $PATH, either remove it from where it is added (which is likely outside of fish since it inherits it), or put the set -e call in your ~/. config/fish/config. fish so it will be executed on every start.

How do I set an environment variable in fish shell?

Instead, simply run set -Ux once at the command line. Universal variables will be stored in the file ~/. config/fish/fish_variables as of Fish 3.0.


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.


As of fish 3.2.0, released in March 2021, the canonical answer is:

fish_add_path /opt/mycoolthing/bin

Existing answer for fish < 3.2.0:

The recommended commands for modifying PATH from fish's maintainers are:

  1. If you want to run the command once:

    set -Ua fish_user_paths /path
    
  2. If you want to add a command to a startup script, this is idempotent:

     contains /path $fish_user_paths; or set -Ua fish_user_paths /path
    

Like all shells, fish inherits its PATH from the environment it is started in. How this is set for login shells differs between operating systems - on Linux, for example, /etc/login.defs controls the initial PATH set for all login shells. I don't know how this is set on OS X.

Next, like bash or csh, the initialisation files for the shell may alter the path. For fish on OS X, there is code in share/fish/config.fish to load paths from the standard OS X path configuration files /etc/paths and /etc/paths.d/*. There is alternative code to set a useful path on Solaris.

There is also code to pick up paths from the universal variable $fish_user_paths, which is the right way to add something to your PATH and have it reflected across all shells.


1. Enumerate user paths:

echo $fish_user_paths | tr " " "\n" | nl

2. Append a new bin path, permanently:

set -ga fish_user_paths my_appended_path

3. Remove 7th bin search path by index: (see #1):

set —eg fish_user_paths[7]