Setting Up Your Bash Environment
Install and configure Bash on Linux, macOS, and Windows (WSL). Set up your terminal, customize your prompt, and configure essential tools.
📖 4 min read📅 2026-02-10Getting Started
Bash on Linux
Bash comes pre-installed on virtually all Linux distributions.
Check Your Bash Version
bash --version
# GNU bash, version 5.2.x
echo $BASH_VERSION
# 5.2.x(1)-releaseUpdate Bash
# Ubuntu/Debian
sudo apt update && sudo apt install bash
# CentOS/RHEL/Fedora
sudo dnf install bash
# Arch Linux
sudo pacman -S bashBash on macOS
macOS Catalina (10.15+) uses Zsh by default, but Bash is still available.
# Check current shell
echo $SHELL
# Switch to Bash
chsh -s /bin/bash
# Install newer Bash via Homebrew
brew install bash
# Add to allowed shells
sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells'
# Set as default
chsh -s /opt/homebrew/bin/bashBash on Windows (WSL)
Windows Subsystem for Linux gives you a real Linux environment:
Install WSL
# Open PowerShell as Administrator
wsl --install
# Install a specific distribution
wsl --install -d Ubuntu-24.04
# List available distributions
wsl --list --onlineConfigure WSL
# After installation, set up your user
# WSL will prompt for username and password
# Update packages
sudo apt update && sudo apt upgrade -y
# Check Bash version
bash --versionTerminal Emulators
Choose a good terminal for the best experience:
Linux
- GNOME Terminal — Default on Ubuntu/Fedora
- Konsole — Default on KDE
- Alacritty — GPU-accelerated, very fast
- Kitty — Feature-rich, GPU-accelerated
macOS
- iTerm2 — The gold standard for macOS
- Terminal.app — Built-in, decent
- Alacritty — Cross-platform, fast
Windows
- Windows Terminal — Modern, supports WSL, tabs
- WSL Terminal — Directly from Start menu
Customizing Your Prompt
The prompt is controlled by the PS1 variable:
# See current prompt
echo $PS1
# Simple custom prompt
PS1="\u@\h:\w\$ "
# Shows: username@hostname:/current/path$
# Colored prompt
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# Green username@host, blue pathPrompt Escape Sequences
| Sequence | Meaning |
|---|---|
\u | Username |
\h | Hostname (short) |
\H | Hostname (full) |
\w | Current directory (full) |
\W | Current directory (basename) |
\d | Date |
\t | Time (24-hour) |
\n | Newline |
\$ | $ for regular user, # for root |
Making It Permanent
Add to your ~/.bashrc:
# Edit .bashrc
nano ~/.bashrc
# Add your custom prompt
PS1='\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
# Reload
source ~/.bashrcEssential Configuration Files
| File | Purpose | When Loaded |
|---|---|---|
/etc/profile | System-wide settings | Login shells |
~/.bash_profile | User login config | Login shells |
~/.bashrc | User interactive config | Interactive non-login shells |
~/.bash_aliases | User aliases | If sourced from .bashrc |
~/.bash_logout | Cleanup on logout | When login shell exits |
Setting Up .bashrc
# ~/.bashrc - Essential configuration
# Don't run if not interactive
case $- in
*i*) ;;
*) return;;
esac
# History settings
HISTCONTROL=ignoreboth # Ignore duplicates and spaces
HISTSIZE=10000
HISTFILESIZE=20000
shopt -s histappend # Append, don't overwrite
# Useful shell options
shopt -s checkwinsize # Update LINES/COLUMNS after each command
shopt -s globstar # ** matches recursively
shopt -s cdspell # Auto-correct minor cd typos
# Aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'
alias mkdir='mkdir -pv'
# Enable color support
if [ -x /usr/bin/dircolors ]; then
eval "$(dircolors -b)"
alias ls='ls --color=auto'
fi
# Custom functions
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Custom prompt
PS1='\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ 'Keyboard Shortcuts
Essential shortcuts for navigating the Bash command line:
| Shortcut | Action |
|---|---|
Ctrl+A | Move to beginning of line |
Ctrl+E | Move to end of line |
Ctrl+U | Delete from cursor to beginning |
Ctrl+K | Delete from cursor to end |
Ctrl+W | Delete word before cursor |
Alt+B | Move back one word |
Alt+F | Move forward one word |
Ctrl+R | Search command history |
Ctrl+L | Clear screen |
Ctrl+C | Cancel current command |
Ctrl+D | Exit shell / EOF |
Ctrl+Z | Suspend current process |
Tab | Auto-complete |
Tab Tab | Show all completions |
!! | Repeat last command |
!$ | Last argument of previous command |
Your First Bash Commands
# Print text
echo "Hello, ShellRAG!"
# Current date and time
date
# Who am I?
whoami
# Where am I?
pwd
# What's in this directory?
ls -la
# System information
uname -a
# Uptime
uptimeNow that your environment is set up, let's learn essential Bash commands!