keepcalculator

06 Numbers and Powers

How to Customize Default Shell on Terminal

Card No. 06·54777 · Updated · Standard formula, shown below

This guide shows you how to change the default shell used by your terminal on Linux and macOS. You’ll learn what a shell is, how to find your current one, and how to switch to another (like Bash, Zsh, or Fish) so every new terminal session starts with your preferred environment.

What You’ll Need

  • Access to a terminal (Terminal.app on macOS, or any terminal emulator on Linux).
  • Administrative (sudo) privileges to change the default shell for your user account.
  • The shell you want to switch to must be installed. Most systems include Bash and Zsh by default; Fish may need to be installed separately.

Step-by-Step

  1. Find your current shell. In the terminal, run: echo $SHELL. This prints the full path of your default shell, e.g., /bin/bash or /bin/zsh. Also check what’s running right now with ps -p $$ — the shell listed there is the one you’re currently using.
  2. List all installed shells. Run cat /etc/shells. This file lists every shell that the system considers valid for login. If the shell you want isn’t listed, you’ll need to install it first (e.g., sudo apt install fish on Debian/Ubuntu, brew install fish on macOS).
  3. Install your desired shell (if needed). For example, to install Fish on Ubuntu: sudo apt update && sudo apt install fish. On macOS with Homebrew: brew install fish. After installation, it will appear in /etc/shells automatically in most cases; if not, you can add it manually with sudo sh -c 'echo /usr/local/bin/fish >> /etc/shells' (adjust the path).
  4. Change the default shell for your user. Use the chsh command (change shell). The syntax is chsh -s /path/to/shell. For example, to switch to Zsh: chsh -s /bin/zsh. You’ll be prompted for your password. This changes the shell for your current user only.
  5. Log out and back in. The change takes effect the next time you log in. To test without logging out, you can start a new terminal window or run exec /bin/zsh to replace the current shell session immediately.
  6. Verify the change. After re-logging in, run echo $SHELL again. It should now show the path to your new shell. Also run ps -p $$ to confirm the running shell matches.
  7. Set up your new shell’s configuration (optional). Each shell uses a different startup file: ~/.bashrc for Bash, ~/.zshrc for Zsh, ~/.config/fish/config.fish for Fish. Add your aliases, environment variables, and prompt customizations there.

Common Mistakes

  • Using the wrong path. The shell path must match exactly what’s in /etc/shells. For example, on macOS, Zsh is at /bin/zsh, but on some Linux distributions it’s at /usr/bin/zsh. Always check with which zsh or type -a zsh.
  • Changing the root user’s shell accidentally. chsh without sudo changes your own shell. If you use sudo chsh, you’ll change the root user’s shell, which can cause issues. Only use sudo if you intend to change another user’s shell.
  • Forgetting to log out. The change won’t apply to existing sessions. You must log out and back in, or start a fresh terminal.
  • Installing a shell but not adding it to /etc/shells. Some package managers don’t automatically add the shell to the list. If chsh complains about an invalid shell, manually add the path as described in Step 3.

Tips

  • Test a shell before making it default. Just run zsh or fish in your terminal to try it out. You can exit back to your original shell with exit.
  • Keep your default shell POSIX-compliant for scripting. If you write scripts that other users might run, sticking with Bash or Zsh is safer because they’re widely available. Fish’s syntax is different and can break scripts.
  • Use a version manager. Tools like chsh only change the login shell. If you use a terminal multiplexer like tmux or screen, they may spawn a different shell. Check their configuration files.
  • Back up your config files. Before editing ~/.bashrc or ~/.zshrc, copy them to a backup file. This makes it easy to revert if you break something.

Troubleshooting

  • chsh says “shell not found” or “invalid shell”. The shell path isn’t in /etc/shells. Add it manually with sudo sh -c 'echo /path/to/shell >> /etc/shells', then try again.
  • After changing, the terminal still opens with the old shell. This can happen if your terminal emulator is configured to run a specific shell. Check the terminal’s preferences (e.g., on macOS Terminal, go to Settings > Profiles > Shell and see if “Run command” is set). Also, ensure you logged out and back in.
  • You get locked out of a shell. If you change to a shell that fails to start (e.g., a broken config), you can still access a shell by pressing Ctrl+Alt+F2 (on Linux) to open a virtual console, or by using the “Recovery Mode” on macOS. Then run chsh -s /bin/bash to revert.
  • Environment variables are missing after switching. Your new shell reads its own startup files. You’ll need to copy or re-export your variables (like PATH) in the new shell’s config file.
  • sudo commands behave differently. Some systems run sudo commands with the root user’s shell. To keep your own shell for sudo, use sudo -s or sudo -i to start a login shell as root.

Frequently Asked Questions

  • What is the default shell on macOS? Since Catalina (10.15), the default is Zsh. Before that, it was Bash 3.2.
  • Can I have different shells for different terminals? Yes. Each terminal emulator can be configured to launch a specific shell. For example, in GNOME Terminal, you can set a custom command in Profile Preferences.
  • Does changing my shell affect cron jobs or scripts? Cron jobs run with /bin/sh by default, not your login shell. Scripts with a shebang line (e.g., #!/bin/bash) will use that interpreter regardless of your default shell.
  • How do I revert to the original shell? Simply run chsh -s /bin/bash (or whatever your original shell’s path was). You can find it in /etc/shells.
  • Is Fish a good default shell? Fish is user-friendly with autosuggestions and a simpler syntax, but it’s not POSIX-compliant, so some scripts may not work. Many users keep Bash or Zsh as default and use Fish interactively.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →