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
- Find your current shell. In the terminal, run:
echo $SHELL. This prints the full path of your default shell, e.g.,/bin/bashor/bin/zsh. Also check what’s running right now withps -p $$— the shell listed there is the one you’re currently using. - 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 fishon Debian/Ubuntu,brew install fishon macOS). - 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/shellsautomatically in most cases; if not, you can add it manually withsudo sh -c 'echo /usr/local/bin/fish >> /etc/shells'(adjust the path). - Change the default shell for your user. Use the
chshcommand (change shell). The syntax ischsh -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. - 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/zshto replace the current shell session immediately. - Verify the change. After re-logging in, run
echo $SHELLagain. It should now show the path to your new shell. Also runps -p $$to confirm the running shell matches. - Set up your new shell’s configuration (optional). Each shell uses a different startup file:
~/.bashrcfor Bash,~/.zshrcfor Zsh,~/.config/fish/config.fishfor 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 withwhich zshortype -a zsh. - Changing the root user’s shell accidentally.
chshwithout sudo changes your own shell. If you usesudo 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
chshcomplains about an invalid shell, manually add the path as described in Step 3.
Tips
- Test a shell before making it default. Just run
zshorfishin your terminal to try it out. You can exit back to your original shell withexit. - 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
chshonly change the login shell. If you use a terminal multiplexer liketmuxorscreen, they may spawn a different shell. Check their configuration files. - Back up your config files. Before editing
~/.bashrcor~/.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 withsudo 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/bashto 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 -sorsudo -ito 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/shby 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
- Turn Off Backup Encryption in iTunes?
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It