191
165

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

fish shellのPATH設定

Last updated at Posted at 2017-10-06

たまにしかやらないのですが、毎回忘れるのでメモします。

結論

一時的な設定

setコマンドと-xオプションを使います。
/usr/local/binを追加するには、次のコマンドを実行します。

set -x PATH /usr/local/bin $PATH

永続的な設定

二つの方法があります。

方法1 設定ファイルを使う

他のshellと似た方法です。
/usr/local/bin/usr/sbinを追加するには、~/.config/fish/config.fish

set PATH /usr/local/bin /usr/sbin $PATH

と書きます。
セッションを起動するたびに環境変数が設定されます。

方法2 fish_user_pathsユニバーサル変数に設定

fish shellではユニバーサル変数という、すべてのセッションで共通の変数を設定できます。
PATHを設定するときは、fish_user_paths変数を使います。

/usr/local/binを追加するには、次のコマンドを実行します。

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

個人的に「なんとなくfish shellっぽい」という理由で、この方法を好んで使っています。

消すときは、次のように/usr/local/binを取り除いた文字列をfish_user_paths変数に設定しなおします。

set -U fish_user_paths (string match -v /usr/local/bin $fish_user_paths)

説明

fish: Tutorialに書いてあります。

$PATH

$PATH is an environment variable containing the directories in which 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

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!)

参考

191
165
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
191
165

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?