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

Update Bash

# Ubuntu/Debian
sudo apt update && sudo apt install bash
 
# CentOS/RHEL/Fedora
sudo dnf install bash
 
# Arch Linux
sudo pacman -S bash

Bash 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/bash

Bash 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 --online

Configure 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 --version

Terminal 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 path

Prompt Escape Sequences

SequenceMeaning
\uUsername
\hHostname (short)
\HHostname (full)
\wCurrent directory (full)
\WCurrent directory (basename)
\dDate
\tTime (24-hour)
\nNewline
\$$ 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 ~/.bashrc

Essential Configuration Files

FilePurposeWhen Loaded
/etc/profileSystem-wide settingsLogin shells
~/.bash_profileUser login configLogin shells
~/.bashrcUser interactive configInteractive non-login shells
~/.bash_aliasesUser aliasesIf sourced from .bashrc
~/.bash_logoutCleanup on logoutWhen 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:

ShortcutAction
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+UDelete from cursor to beginning
Ctrl+KDelete from cursor to end
Ctrl+WDelete word before cursor
Alt+BMove back one word
Alt+FMove forward one word
Ctrl+RSearch command history
Ctrl+LClear screen
Ctrl+CCancel current command
Ctrl+DExit shell / EOF
Ctrl+ZSuspend current process
TabAuto-complete
Tab TabShow 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
uptime

Now that your environment is set up, let's learn essential Bash commands!