Skip to content

Instantly share code, notes, and snippets.

@gagarine
Last active December 19, 2024 11:40
Show Gist options
  • Save gagarine/cf3f65f9be6aa0e105b184376f765262 to your computer and use it in GitHub Desktop.
Save gagarine/cf3f65f9be6aa0e105b184376f765262 to your computer and use it in GitHub Desktop.
Install fish shell on macOS Mojave with brew

Installing Fish shell on MacOS (Intel and M1) using brew

Fish is a smart and user-friendly command line (like bash or zsh). This is how you can instal Fish on MacOS and make your default shell.

Note that you need the https://brew.sh/ package manager installed on your machine.

Install Fish

brew install fish

More info: https://fishshell.com/docs/current/tutorial.html#tut_path

Check the path

Check the fish path with which fish . In the examples below it was located at: /opt/homebrew/bin/fish On older Macs default path is /usr/local/bin/fish, replace accordingly in the instruction below.

Make fish the default shell

MacOS allow you to change your default Shell using comande line or GUI methodes https://support.apple.com/en-us/102360.

Using the terminal:

  1. check the fish path with which fish. In the examples below it was located at: /opt/homebrew/bin/fish. On older Macs the path might differ.
  2. chsh -s /opt/homebrew/bin/fish

Add brew binaries in fish path

run the command: fish_add_path /opt/homebrew/bin

Optionnal Configurations

Auto Completions

To collect command completions for all commands run:

fish_update_completions

Edit config.sh

I edited the ~/.config/fish/config.fish to have my terminal in english

set -x LANG en_US.UTF-8

Configure your shell

You can configure your shell by launching the web interface, run:

fish_config

Related documentation

@gagarine
Copy link
Author

gagarine commented Nov 14, 2021 via email

@gunmefatale
Copy link

gunmefatale commented Nov 15, 2021

Can you explain the number 6 in more detail?
Where should I put set -U fish_user_paths /opt/homebrew/bin/ $fish_user_paths ?
I proceeded to step 5, but the brew input in the terminal is not working.

@usagizmo
Copy link

I think the / at the end of the path is unnecessary.

set -U fish_user_paths /opt/homebrew/bin/ $fish_user_paths
which fish #=> /opt/homebrew/bin//fish

set -U fish_user_paths /opt/homebrew/bin $fish_user_paths
which fish #=> /opt/homebrew/bin/fish

@gagarine
Copy link
Author

@usagizmo that right, I checked https://fishshell.com/docs/current/cmds/fish_add_path.html and / do not seem necessary.

@vuhaianh1990
Copy link

Love it!! ❤️

@mesqueeb
Copy link

@gagarine how can I make a PR towards this doc again?

You have a typo here:

This is how you can instal Fish on MacOS and make your defaul shell.

Should be:

This is how you can instal Fish on MacOS and make your default shell.

@gagarine
Copy link
Author

@mesqueeb you cannot on gist. But thanks I fixed the typo.

@arthus05
Copy link

arthus05 commented Apr 7, 2022

Saved me. Thank you!!! 🙏🏽

@turnerburchard
Copy link

Thank you! This tutorial should be on the front page of homebrew/fish/macOS

@sanderDijkxhoorn
Copy link

Thanks for the /opt/homebrew/bin/fish path :)

@Nepoxx
Copy link

Nepoxx commented Jul 19, 2022

I would recommend the following:

set -g fish_complete_path $fish_complete_path /opt/homebrew/share/fish/vendor_completions.d

since some homebrew packages will add completions there and fish doesn't look for completion in that folder by default

@dinkopehar
Copy link

At 6th step:

Add brew binaries in fish path run the command: set -U fish_user_paths /opt/homebrew/bin $fish_user_paths

can be modified to include newer way of modifying Fish path as:

Add brew binaries in fish path run the command: fish_add_path /opt/homebrew/bin

@alexleeca
Copy link

You save my day, thx!

@victorhooi
Copy link

@dinko-pehar Awesome - this worked for me, for adding the Homebrew BIN path to my fish shell:

fish_add_path /opt/homebrew/bin

Is there also a current recommended command to setup command completions for fish/brew?

@dinkopehar
Copy link

@victorhooi You can just use:

fish_update_completions

to collect command completions for all commands. Some are also collected from automatically when you install some package via brew because it provides fish completions.


You can read my blog how I set up Fish shell and converted ZSH config to Fish at https://pehar.dev/blog/from-zsh-to-fish/

@gagarine
Copy link
Author

gagarine commented Oct 4, 2022

The doc was updated from the suggestions in the various comments. Thanks to all!

@Nepoxx the fish installed with brew add /opt/homebrew/share/fish/vendor_completions.d for completion (if not, it's a bug that need to be reported to brew)

@alper
Copy link

alper commented Feb 1, 2023

I'm setting up a new mac and confused about whether I used omf or fisher. Is this settled now?

@ahoho
Copy link

ahoho commented Feb 12, 2023

Shouldn't we also have the following in ~/.config/fish/config.fish?

if status is-interactive
    eval "$(brew shellenv)"
end

@phromaj
Copy link

phromaj commented Feb 13, 2023

Hi everyone, I get this error when I set fish as my default shell.

error: can not save history
warning-path: Unable to locate data directory derived from $HOME: '/Users/user/.local/share/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

Does anyone know why?

Thanks

EDIT  : fixed the problem, don't know why but ~/.local was created by root, so I deleted it and created again with my $USER

@antonengelhardt
Copy link

@phromaj I get that too:

Last login: Mon Feb 13 08:51:19 on ttys015
error: can not save universal variables or functions
warning-path: Unable to locate config directory derived from $HOME: '/Users/antonengelhardt/.config/fish'.
warning-path: The error was 'File exists'.
warning-path: Please set $HOME to a directory where you have write access.

mkdir: /completions: Read-only file system
mkdir: /conf.d: Read-only file system
mkdir: /functions: Read-only file system
warning: An error occurred while redirecting file '/config.fish'
open: Read-only file system
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fis

@antonengelhardt
Copy link

Just fixed it lol.

I used symlinks pointing from my dotfiles directory to the .config/fish... When i moved the fish folder back it solved it

@fnxr21
Copy link

fnxr21 commented May 21, 2023

in case anyone wants the complete guide for Apple Silicon (M1+) Macs:

Installing fish

brew install fish

https://fishshell.com

Fallback

To fall back to another shell for something, just type zsh or bash. It will temporarily change the shell until you restart your terminal. You can also type fish again to go back to fish.

Make fish the default

  1. check the fish path with which fish. In the examples below it was located at: /opt/homebrew/bin/fish
    On older Macs these paths might differ.
  2. Add fish to the know shells
    sudo sh -c 'echo /opt/homebrew/bin/fish >> /etc/shells'
  3. Restart your terminal
  4. Set fish as the default shell
    chsh -s /opt/homebrew/bin/fish
  5. Restart your terminal and check if it launched with fish or not
  6. Add brew binaries in fish path
    set -U fish_user_paths /opt/homebrew/bin/ $fish_user_paths

thats working ,thanks bro

@mrLuisFer
Copy link

in case anyone wants the complete guide for Apple Silicon (M1+) Macs:

Installing fish

brew install fish

https://fishshell.com

Fallback

To fall back to another shell for something, just type zsh or bash. It will temporarily change the shell until you restart your terminal. You can also type fish again to go back to fish.

Make fish the default

  1. check the fish path with which fish. In the examples below it was located at: /opt/homebrew/bin/fish
    On older Macs these paths might differ.
  2. Add fish to the know shells
    sudo sh -c 'echo /opt/homebrew/bin/fish >> /etc/shells'
  3. Restart your terminal
  4. Set fish as the default shell
    chsh -s /opt/homebrew/bin/fish
  5. Restart your terminal and check if it launched with fish or not
  6. Add brew binaries in fish path
    set -U fish_user_paths /opt/homebrew/bin/ $fish_user_paths

For MacOs chip M1 (v13.4.1) it worked correctly 🤝

@dony-wiranata
Copy link

It works nicely - thank you!

Just a sanity check, in case you fail at step 4. Set fish as the default shell (as in, when you re-open Terminal and fish does not get launched automatically), please ensure that in your Terminal app > General > Shells open with, it has Default login shell as the value, instead of Command (complete path).

image

@samuel-gibbon
Copy link

Worked perfect for me on M3, thanks

@santakdalai90
Copy link

Thanks for sharing. It helped a lot.

@sertugkaya
Copy link

Thanks for the tip! 👍 fish docs does not show the correct location as you mentioned :)

@jagdishadusumalli
Copy link

macos Sonoma 14.5

  1. Add brew binaries in fish path
    echo (echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> ~/.config/fish/config.fish

This is the conventional way/ command to add brew libs to the path in bash or zsh shell.
In fish when i executed got error "fish: command substitutions not allowed here"
adding extra echo at the begining resolves the error and adds the path to the config.fish file properly and works

@injust
Copy link

injust commented Sep 19, 2024

  1. check the fish path with which fish. In the examples below it was located at: /opt/homebrew/bin/fish. On older Macs the path might differ.
  2. Add fish to the know shells run the command: sudo sh -c 'echo /opt/homebrew/bin/fish >> /etc/shells'
  3. Restart your terminal
  4. Set fish as the default shell run the command: chsh -s /opt/homebrew/bin/fish
  5. Restart your terminal and check if it launched with fish or not

Editing /etc/shells manually is a terrible hack. Use the official method instead:

  1. Choose Apple menu  > System Settings, then click Users & Groups in the sidebar.
  2. Control-click your user name or user picture in the list of users on the right, then choose Advanced Options.
  3. Enter your user name and password when prompted.
  4. Choose a shell from the “Login shell” menu, then click OK to save the changes.

This lets you specify the path to the shell of your choice, even if it isn't in /etc/shells.

@gagarine
Copy link
Author

Thanks all, I updated the gist. (I don't use fish myself, but the gist seems quiet popular, so I feel that it needed an update :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment