How can I set my default shell on a Mac, e.g. to Fish?

MacosTerminalFish

Macos Problem Overview


I do not like to retype fish every time I start terminal. I want Fish on by default. How can I set the Fish shell as my default shell on a Mac?

Macos Solutions


Solution 1 - Macos

1. sudo nano /etc/shells enter image description here

2. add /usr/local/bin/fish to your list of shells enter image description here

3. chsh -s /usr/local/bin/fish

Solution 2 - Macos

From Terminal:

  1. Add Fish to /etc/shells, which will require an administrative password:

    sudo echo /usr/local/bin/fish >> /etc/shells
    
  2. Make Fish your default shell with chsh:

    chsh -s /usr/local/bin/fish
    

From System Preferences:

  1. User and Groups → ctrl-click on Current User → Advanced Options...

  2. Change Login shell to /usr/local/bin/fish

    login shell

  3. Press OK, log out and in again

Solution 3 - Macos

You can use chsh to change a user's shell.

Run the following code, for instance, to change your shell to Zsh

chsh -s /bin/zsh

As described in the manpage, and by Lorin, if the shell is not known by the OS, you have to add it to its known list: /etc/shells.

Solution 4 - Macos

These are applicable to macOS v10.12.5 (Sierra) (16F73) and probably some other recent and upcoming versions of macOS.

  1. chsh is not enough to change the default shell. Make sure you press Command + , while your terminal is open and change the 'Shells open with' option to 'Default login shell.'

  2. In case of Bash, make sure that you execute echo $BASH_VERSION to confirm you are running the intended version of Bash. bash --version does not give you correct information.

Solution 5 - Macos

Here's another way to do it:

Assuming you installed it with MacPorts, which can be done by doing:

sudo port install fish

Your shell will be located in /opt/local/bin/fish.

You need to tell OS X that this is a valid shell. To do that, add this path to the end of the /etc/shells file.

Once you've done this, you can change the shell by going to System PreferencesAccounts. Click on the Lock to allow changes. Right-click on the account, and choose "Advanced Options...". In the "Login shell" field, add the path to Fish.

Solution 6 - Macos

Terminal.appPreferencesGeneralShells open with/bin/fish
  1. Open your terminal and press command + , (comma). This will open a preferences window.
  2. The first tab is 'General'.
  3. Find 'Shells open with' setting and choose the second option which needs complete path to the shell.
  4. Paste the link to your fish command, which generally is /usr/local/bin/fish.

See this screenshot where zsh is being set as default.

Screenshot of entering /bin/zsh in Terminal.app preferences

I am using macOS v10.12 (Sierra). It also works in macOS v10.14 (Mojave).

Solution 7 - Macos

The only thing that worked for me was a combination of all these methods.

  1. First I had to add the path to the Fish executable to the /etc/shells file

  2. Then I ran chsh -s /usr/local/bin/fish

  3. Finally, I typed Command + , and added /usr/local/bin/fish to the default path there

Only after I had done all three things did Fish start popping up as the default for new terminal windows.

Solution 8 - Macos

On macOS v10.14 (Mojave) I had to do the following (using Z shell (zsh) as an example):

brew install zsh
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)

Solution 9 - Macos

How to get the latest version of Bash on modern macOS (tested on macOS v10.14 (Mojave)).

brew install bash
which bash | sudo tee -a /etc/shells
chsh -s $(which bash)

Then you are ready to get Vim-style tab completion which is only available on Bash >= 4 (the current version in Homebrew is 5.0.2):

# If there are multiple matches for completion, Tab should cycle through them
bind 'TAB':menu-complete

# Display a list of the matching files
bind "set show-all-if-ambiguous on"

# Perform partial completion on the first Tab press,
# only start cycling full results on the second Tab press
bind "set menu-complete-display-prefix on"

Solution 10 - Macos

This work for me on fresh install of Mac OS X v10.12 (Sierra):

  1. Define the current user as the owner of shells

    sudo chown $(whoami) /etc/shells
    
  2. Add Fish to file /etc/shells

    sudo echo /usr/local/bin/fish >> /etc/shells
    
  3. Make Fish your default shell with chsh

    chsh -s /usr/local/bin/fish
    
  4. Redefine root as the owner of shells

    sudo chown root /etc/shells
    

Solution 11 - Macos

The chsh program will let you change your default shell. It will want the full path to the executable, so if your shell is Fish then it will want you to provide the output given when you type which fish.

You'll see a line starting with "Shell:". If you've never edited it, it most likely says "Shell: /bin/bash". Replace that /bin/bash path with the path to your desired shell.

Solution 12 - Macos

When in the Terminal, open the terminal preferences using Command+,.

On the General Tab, Shells open with: change from Default login shell to Command: and using /bin/fish

Solution 13 - Macos

Homebrew on M1 Macs should use /opt/homebrew instead of /usr/local.

You can check the Fish location which fish. For me, Fish was in /opt/homebrew/bin/fish which was the location I have added to etc/shells.

Solution 14 - Macos

  • type fish to check if it was installed correctly, if installed correctly, type exit
  • type which fish, copy the path.
  • type sudo sh -c 'echo <your-fish-path-here> >> /etc/shells'
  • restart your terminal
  • type chsh -s <your-fish-path-here>
  • restart terminal again
  • it should work now.

Solution 15 - Macos

Use dscl:

heimdall:~ leeg$ dscl
Entering interactive mode... (type "help" for commands)
 > cd /Local/Default/Users/
/Local/Default/Users > read <<YOUR_USER>>
[...]
UserShell: /bin/bash
/Local/Default/Users >

Just change that value (with the write command in dscl).

Solution 16 - Macos

In case you are having troubles with the other ways, the following worked on macOS v10.14 (Mojave), but it should generally work.

which fish

Add the output path to System PreferencesUsers & Groups → right click user, Advanced Options. Paste the result from which into filed "Login shell:".

Solution 17 - Macos

To change your default shell on Mac, run the following:

chsh -s <name-of-shell>

The list of shells you can choose from are:

  1. /bin/bash
  2. /bin/csh
  3. /bin/dash
  4. /bin/ksh
  5. /bin/sh
  6. /bin/tcsh
  7. /bin/zsh

so if you want to change from to the /bin/zsh shell, your command will look like:

chsh -s /bin/zsh

You can see all the available shells on your system by running:

cat /etc/shells

Solution 18 - Macos

Edit file .zshrc and change it to

exec /bin/bash

Or to whatever shell you might prefer.

Bonus: this doesn't require root access and will work on every version of OS X.

The only problem is that it doesn't read file .bash_profile this way; it is only read if Bash is run as an interactive login shell. You would have to include it from file .bashrc with something like this:

if [[ "$OSTYPE" == "darwin"* ]]; then
    #local hack on osx.
    if [[ -f $HOME/.bash_profile ]]; then
      . $HOME/.bash_profile
    fi
fi

Also: The bash version that comes with osx is a bit dated, it is preferrable to install an up to date version of bash with brew install bash; in this case your .zshrc file should run the correct bash version. Currently that is

exec /usr/local/Cellar/bash/5.1.8/bin/bash

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionL&#233;o L&#233;opold Hertz 준영View Question on Stackoverflow
Solution 1 - Macosuser391339View Answer on Stackoverflow
Solution 2 - MacosPaolo MorettiView Answer on Stackoverflow
Solution 3 - MacosAifView Answer on Stackoverflow
Solution 4 - MacosTushar VaziraniView Answer on Stackoverflow
Solution 5 - MacosLorin HochsteinView Answer on Stackoverflow
Solution 6 - MacosPankajView Answer on Stackoverflow
Solution 7 - MacosquaintmView Answer on Stackoverflow
Solution 8 - MacosMagicDude4EvaView Answer on Stackoverflow
Solution 9 - MacosBruno BronoskyView Answer on Stackoverflow
Solution 10 - MacosZecKaView Answer on Stackoverflow
Solution 11 - MacosrejjView Answer on Stackoverflow
Solution 12 - MacosholsetyView Answer on Stackoverflow
Solution 13 - MacosBlackView Answer on Stackoverflow
Solution 14 - MacosAsh SinghView Answer on Stackoverflow
Solution 15 - Macosuser23743View Answer on Stackoverflow
Solution 16 - MacosSLuckView Answer on Stackoverflow
Solution 17 - MacoscodedbychavezView Answer on Stackoverflow
Solution 18 - MacosMichaelMoserView Answer on Stackoverflow