[macos] How to set my default shell on Mac?

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

This question is related to macos terminal fish

The answer is


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.


Terminal.app > Preferences > General > Shells 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 2nd 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 <code>/bin/zsh</code> in Terminal.app preferences

I am using macOS Sierra. Also works in macOS Mojave.


How to get the latest version of bash on modern macOS (tested on 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 (current version in brew 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"

In case you are having troubles with the other ways, worked on mac Mojave but should generally work.

which fish

add the output path to "System Preferences > Users & Groups > right click user, Advanced Options" Paste the result from which into "Login shell:"


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


How to get the latest version of bash on modern macOS (tested on 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 (current version in brew 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"

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.


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 OSX 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 Preferences -> Accounts. 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.


This work for me on fresh install of mac osx (sierra):

  1. Define current user as owner of shells
sudo chown $(whoami) /etc/shells
  1. Add Fish to /etc/shells
sudo echo /usr/local/bin/fish >> /etc/shells
  1. Make Fish your default shell with chsh
chsh -s /usr/local/bin/fish
  1. Redefine root as owner of shells
sudo chown root /etc/shells


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


edit .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 osx.

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

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

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


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


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

  1. First I had to add fish 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.


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.


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


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.


edit .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 osx.

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

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

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.


To change your default shell on mac run the following:

chsh -s <name-of-shell>

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

This work for me on fresh install of mac osx (sierra):

  1. Define current user as owner of shells
sudo chown $(whoami) /etc/shells
  1. Add Fish to /etc/shells
sudo echo /usr/local/bin/fish >> /etc/shells
  1. Make Fish your default shell with chsh
chsh -s /usr/local/bin/fish
  1. Redefine root as owner of shells
sudo chown root /etc/shells

On macOS Mojave I had to do the following (using zsh as an example):

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

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 OSX 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 Preferences -> Accounts. 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.



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.


Terminal.app > Preferences > General > Shells 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 2nd 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 <code>/bin/zsh</code> in Terminal.app preferences

I am using macOS Sierra. Also works in macOS Mojave.


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

On the Setting Tab, select one of the themes, and choose the shell tab on the right.

You can set the autostart command fish.


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.


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

On the Setting Tab, select one of the themes, and choose the shell tab on the right.

You can set the autostart command fish.


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

  1. First I had to add fish 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.


To change your default shell on mac run the following:

chsh -s <name-of-shell>

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

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


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


In case you are having troubles with the other ways, worked on mac Mojave but should generally work.

which fish

add the output path to "System Preferences > Users & Groups > right click user, Advanced Options" Paste the result from which into "Login shell:"


On macOS Mojave I had to do the following (using zsh as an example):

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

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



Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to fish

Define an alias in fish shell How to set my default shell on Mac?