What Are Shells?
A shell is a program that provides a text-based interface to your operating system. The most common shells are:- Zsh (Z Shell) - The default on macOS since Catalina (10.15)
- Bash (Bourne Again Shell) - The default on most Linux distributions and older macOS versions
- Fish (Friendly Interactive Shell) - A modern shell with user-friendly features
- Sh (Bourne Shell) - The original Unix shell, basic and minimal
Determine Your Current Shell
Run this command to see which shell you’re using:/bin/bash- You’re using Bash/bin/zsh- You’re using Zsh/usr/bin/fishor/bin/fish- You’re using Fish/bin/sh- You’re using Sh
The
$SHELL variable shows your default shell. To see which shell is currently running, use: ps -p $$Shell Configuration Files
Each shell has specific configuration files where you can set persistent environment variables.You’ll notice many configuration files end with “rc” (like
.bashrc, .zshrc). The “rc” stands for “run commands” - these files contain commands that run automatically when you start a new shell session. This is where you can set environment variables, aliases, and other shell preferences that persist across sessions.Bash
Configuration file:~/.bashrc (Linux) or ~/.bash_profile (macOS)
Zsh
Configuration file:~/.zshrc
Fish
Configuration file:~/.config/fish/config.fish
Fish uses a different syntax for setting environment variables:
Where Are Configuration Files Located?
The~ symbol represents your home directory. The actual path depends on your username:
- Linux/macOS:
/home/username/or/Users/username/ - Windows (WSL):
/home/username/
.) are hidden by default. To see them:
Quick Reference
| Shell | Check Command | Config File | Export Syntax |
|---|---|---|---|
| Bash | echo $SHELL | ~/.bashrc or ~/.bash_profile | export VAR="value" |
| Zsh | echo $SHELL | ~/.zshrc | export VAR="value" |
| Fish | echo $SHELL | ~/.config/fish/config.fish | set -gx VAR "value" |
Switching Shells
If you want to change your default shell:Troubleshooting
Environment Variable Not Persisting
If your environment variable disappears when you open a new terminal:- Verify you added it to the correct config file for your shell
- Make sure you saved the file after editing
- Close and reopen your terminal (or run
sourcecommand)
Can’t Find Config File
If your config file doesn’t exist, create it:Changes Not Taking Effect
After editing your config file, you must either:- Run
source ~/.zshrc(or your specific config file) - Close and reopen your terminal