The macOS Terminal Setup

5 minute read

macOS is built on BSD Unix — a cousin of Linux, not Linux itself. For most everyday use, the commands are the same. But there are important differences in tools and flags. This page shows you how to set up macOS to behave more like Linux, and how to maximise your terminal productivity.


The macOS vs Linux: Key Differences

macOS uses BSD versions of core utilities, while Linux uses GNU versions. The flags sometimes differ:

# Example: ls on Linux vs macOS
# Linux (GNU ls)
ls -l --color=auto    # --color is a long flag that works
ls -la --group-directories-first   # GNU-specific flag

# macOS (BSD ls)
ls -l                 # works
ls -l --color=auto    # ERROR: illegal option -- -
ls -la -G             # -G enables colour on macOS BSD ls

# Example: date
# Linux (GNU date)
date -d "yesterday" +%Y-%m-%d         # works
date -d "next Monday" +%Y-%m-%d       # works

# macOS (BSD date)
date -d "yesterday" +%Y-%m-%d         # ERROR: illegal option -- d
date -v-1d +%Y-%m-%d                  # macOS equivalent

The solution: install GNU tools via Homebrew.


Step 1: Install Homebrew

Homebrew is the essential macOS package manager. Think of it as apt for macOS:

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Follow the post-install instructions to add brew to PATH
# For Apple Silicon (M1/M2/M3):
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

# For Intel Mac:
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"

# Verify installation
brew --version
# Homebrew 4.2.0

Step 2: Install GNU Core Utilities

Replace macOS BSD tools with Linux-compatible GNU tools:

# Install GNU coreutils (ls, cp, mv, rm, cat, chmod, etc.)
brew install coreutils

# Install GNU sed (stream editor — flags differ from BSD sed)
brew install gnu-sed

# Install GNU awk
brew install gawk

# Install GNU find (gfind — flags compatible with Linux find)
brew install findutils

# Install GNU grep (supports Perl regex -P flag)
brew install grep

# GNU tools are installed with 'g' prefix to avoid conflicts:
# gls, gsed, gawk, gfind, ggrep

# To use them WITHOUT the 'g' prefix (make them default):
# Add to ~/.zshrc:
export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/gawk/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/grep/libexec/gnubin:$PATH"

After adding to ~/.zshrc and restarting your terminal:

# Verify GNU tools are active
ls --version | head -1
# ls (GNU coreutils) 9.4

sed --version | head -1
# GNU sed 4.9

# Now Linux commands work on macOS:
ls --color=auto
date -d "yesterday" +%Y-%m-%d    # Still macOS date, not GNU date — install gnu-date separately if needed

Step 3: Install iTerm2

iTerm2 is a superior replacement for the macOS Terminal app:

# Install via Homebrew
brew install --cask iterm2

# Or download from: https://iterm2.com/

iTerm2 key advantages over Terminal.app:

Feature Terminal.app iTerm2
Split panes No Yes (Cmd+D horizontal, Cmd+Shift+D vertical)
Search history Basic Regex + highlight
Profiles Basic Full customisation
Hotkey window No Yes (dropdown like Quake)
Shell integration No Yes (marks commands, shows timing)
Inline images No Yes
Tab colours No Yes

Useful iTerm2 shortcuts:

Cmd + D          → Split pane vertically
Cmd + Shift + D  → Split pane horizontally
Cmd + T          → New tab
Cmd + W          → Close pane/tab
Cmd + [  / ]     → Switch panes
Cmd + 1/2/3      → Switch to tab 1/2/3
Cmd + F          → Find in current buffer (supports regex)

Step 4: Install oh-my-zsh

oh-my-zsh supercharges the zsh shell (macOS default since Catalina):

# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# oh-my-zsh replaces your ~/.zshrc — back it up first if you have custom config

Useful oh-my-zsh Plugins

Edit ~/.zshrc to enable plugins:

# Open .zshrc
vim ~/.zshrc

# Find the plugins line and add:
plugins=(
    git           # Git aliases (gs=status, gp=pull, gl=log, etc.)
    sudo          # Press Esc twice to prepend sudo to last command
    history       # Better history search
    macos         # Mac-specific aliases (ofd = open Finder here, etc.)
    docker        # Docker command completion
    kubectl       # kubectl autocompletion and aliases
    aws           # AWS CLI completion
    z             # Jump to frequently visited dirs: z projects
)

# Apply changes
source ~/.zshrc

Install a Better Theme

# Install Powerlevel10k — the most popular zsh theme
brew install powerlevel10k

# Add to ~/.zshrc:
echo 'source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme' >> ~/.zshrc

# Run the configuration wizard
p10k configure
# Answer the visual questions to set up your preferred prompt style

Step 5: Install Essential Dev Tools

# Version control
brew install git

# Git diff viewer
brew install git-delta

# File viewers
brew install bat      # cat with syntax highlighting
brew install eza      # modern ls replacement (like exa)

# Search tools
brew install ripgrep   # rg — fast grep
brew install fd         # fd — fast find

# JSON/YAML tools
brew install jq         # JSON processor
brew install yq         # YAML processor

# Network tools
brew install curl wget httpie

# Terminal multiplexer
brew install tmux

# System monitoring
brew install htop

# Cloud tools
brew install awscli
brew install --cask google-cloud-sdk
brew install azure-cli

# Infrastructure tools
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Step 6: Configure ~/.zshrc

A well-organised ~/.zshrc makes terminal work much more productive:

# ~/.zshrc — macOS/Linux compatible configuration

# ── Homebrew ───────────────────────────────────────────────────
eval "$(/opt/homebrew/bin/brew shellenv)"   # Apple Silicon
# eval "$(/usr/local/bin/brew shellenv)"    # Intel — uncomment if needed

# ── GNU Tools (Linux-compatible) ───────────────────────────────
export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/gawk/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/grep/libexec/gnubin:$PATH"

# ── oh-my-zsh ──────────────────────────────────────────────────
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(git sudo history macos docker kubectl aws z)
source $ZSH/oh-my-zsh.sh

# ── Aliases ────────────────────────────────────────────────────
alias ll='ls -alh --color=auto'
alias la='ls -A'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'

# Git aliases
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline --graph --decorate'

# ── Environment Variables ──────────────────────────────────────
export EDITOR=vim
export VISUAL=vim
export HISTSIZE=10000
export HISTFILESIZE=20000

# ── Apply Powerlevel10k ────────────────────────────────────────
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh

Key Takeaways

  • macOS uses BSD tools — flags differ from Linux (GNU) tools
  • Installing coreutils, gnu-sed, gawk via Homebrew gives you Linux-compatible commands
  • iTerm2 is significantly better than Terminal.app for split panes, search, and profiles
  • oh-my-zsh with the git, sudo, and z plugins dramatically speeds up daily terminal work
  • Powerlevel10k provides a highly informative prompt (git status, AWS profile, Python venv)
  • Keep ~/.zshrc organised — split into sections with comments

← Back to WSL2 on Windows Next → Cloud Shell (AWS & GCP)

Updated: