macOS Dev Environment Setup — Xcode CLI, Terminal, and Shell Configuration

The Starting Point for macOS Development

macOS is a Unix-based operating system with a terminal environment optimized for development. However, in its default state, essential tools like Git and compilers are missing. Installing Xcode Command Line Tools is the first step in any development environment setup.

This article walks through Xcode CLI tool installation, zsh/Oh My Zsh setup, iTerm2 customization, and development toolchain configuration step by step.

Installing Xcode Command Line Tools

Xcode CLI tools include Git, make, clang (C/C++ compiler), header files, and other basic development tools. You only need to install the CLI tools, not the full Xcode.

# Install Xcode CLI tools
xcode-select --install
# Click "Install" in the popup dialog
# Download size: ~1.5GB, installation time: 5-10 minutes

# Verify installation
xcode-select -p
# Output: /Library/Developer/CommandLineTools

# Check included tools
git --version     # git version 2.39.5 (Apple Git-154)
make --version    # GNU Make 3.81
clang --version   # Apple clang version 16.0.0

If the Xcode CLI tools are outdated, you can delete and reinstall them.

# Remove and reinstall existing CLI tools
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

zsh Basic Configuration

Since macOS Catalina, the default shell has been zsh. Configure environment variables, aliases, and functions in the .zshrc file.

# Check current shell
echo $SHELL
# Output: /bin/zsh

# Create/edit .zshrc file
touch ~/.zshrc

# Basic .zshrc configuration
cat << 'ZSHRC' >> ~/.zshrc
# Default environment variables
export LANG=en_US.UTF-8
export EDITOR="code --wait"

# Homebrew (Apple Silicon)
eval "$(/opt/homebrew/bin/brew shellenv)"

# History settings
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
setopt SHARE_HISTORY          # Share history across terminals
setopt HIST_IGNORE_DUPS       # Ignore consecutive duplicate commands
setopt HIST_IGNORE_SPACE      # Exclude commands starting with space

# Convenient aliases
alias ll="ls -la"
alias gs="git status"
alias gd="git diff"
alias gl="git log --oneline -20"
alias dc="docker compose"
alias python="python3"
alias pip="pip3"

# Directory navigation shortcuts
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
ZSHRC

# Apply settings
source ~/.zshrc

Oh My Zsh Installation and Setup

Oh My Zsh is a zsh configuration framework that makes it easy to manage themes, plugins, and auto-completion.

# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Existing .zshrc is backed up as .zshrc.pre-oh-my-zsh

# Install useful plugins
# zsh-autosuggestions: history-based auto-completion
git clone https://github.com/zsh-users/zsh-autosuggestions \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# zsh-syntax-highlighting: command syntax highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# fzf: fuzzy finder
brew install fzf
$(brew --prefix)/opt/fzf/install

Configure the theme and plugins in .zshrc.

# ~/.zshrc modifications (Oh My Zsh related sections)

# Theme setting (built-in theme)
ZSH_THEME="agnoster"
# Popular themes: agnoster, robbyrussell, powerlevel10k

# Enable plugins
plugins=(
    git                    # Git alias collection (gst, gco, gcmsg, etc.)
    zsh-autosuggestions    # History-based auto-completion
    zsh-syntax-highlighting # Command syntax highlighting
    fzf                    # Fuzzy search
    docker                 # Docker auto-completion
    node                   # Node.js auto-completion
    python                 # Python virtualenv display
    brew                   # Homebrew auto-completion
)

Powerlevel10k Theme (Advanced)

For a more powerful prompt, Powerlevel10k is recommended.

# Install Nerd Font (required for icons)
brew install --cask font-jetbrains-mono-nerd-font

# Install Powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

# Change theme in ~/.zshrc
# ZSH_THEME="powerlevel10k/powerlevel10k"

# Run configuration wizard (auto-runs on terminal restart)
p10k configure
# Interactive wizard for choosing prompt style
# Can display Git status, execution time, Node/Python version, etc.

iTerm2 Setup

iTerm2 offers more features than the default macOS terminal.

# Install iTerm2
brew install --cask iterm2

# Recommended settings (configure in iTerm2 → Settings)
# Appearance → Theme: Minimal
# Profiles → Text → Font: JetBrains Mono Nerd Font, 14pt
# Profiles → Window → Transparency: 5~10%
# Profiles → Terminal → Scrollback lines: 10000
# Profiles → Keys → Key Mappings → Presets: Natural Text Editing

You can export iTerm2 profiles as JSON and manage them with Git.

# Export iTerm2 settings
# iTerm2 → Settings → General → Preferences
# Check "Load preferences from a custom folder"
# Path: ~/dotfiles/iterm2

# Or check settings via command line
defaults read com.googlecode.iterm2

Development Toolchain Installation

Install key development tools via Homebrew.

# Essential CLI tools
brew install git wget curl jq tree

# Modern CLI tools (default command replacements)
brew install bat      # cat replacement (syntax highlighting)
brew install eza      # ls replacement (icons, tree view)
brew install ripgrep  # grep replacement (fast search)
brew install fd       # find replacement (intuitive syntax)
brew install zoxide   # cd replacement (smart navigation)
brew install tldr     # man replacement (concise help)

# Add aliases to .zshrc
cat << 'ALIASES' >> ~/.zshrc

# Modern CLI aliases
alias cat="bat --paging=never"
alias ls="eza --icons"
alias ll="eza -la --icons --git"
alias tree="eza --tree --icons"
alias grep="rg"
alias find="fd"
ALIASES

Per-Language Setup

# Node.js (version management with nvm)
brew install nvm
mkdir ~/.nvm
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh"' >> ~/.zshrc
source ~/.zshrc
nvm install --lts
node --version
# Sample output: v22.12.0

# Python (version management with pyenv)
brew install pyenv
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
pyenv install 3.12.8
pyenv global 3.12.8
python --version
# Sample output: Python 3.12.8

# Go
brew install go
echo 'export GOPATH="$HOME/go"' >> ~/.zshrc
echo 'export PATH="$GOPATH/bin:$PATH"' >> ~/.zshrc

# Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Output: Rust is installed now.

Git Configuration

Essential Git settings when first using it on macOS.

# Basic settings
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"

# macOS specific: ignore .DS_Store
echo ".DS_Store" >> ~/.gitignore_global
git config --global core.excludesFile ~/.gitignore_global

# Generate SSH key (Ed25519)
ssh-keygen -t ed25519 -C "email@example.com"
# Set passphrase

# Add SSH key to macOS Keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

# SSH config setup
cat << 'SSH' >> ~/.ssh/config
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
    AddKeysToAgent yes
    UseKeychain yes
SSH

# Copy public key (for GitHub registration)
pbcopy < ~/.ssh/id_ed25519.pub
# Copied to clipboard → paste into GitHub Settings → SSH Keys

Practical Tips

  • Manage dotfiles: Managing .zshrc, .gitconfig, Brewfile, etc. in a Git repo makes new Mac setup fast
  • Nerd Font required: Tools with icons like Oh My Zsh, Powerlevel10k, and eza require a Nerd Font
  • Rosetta 2: If Intel-only tools are needed on Apple Silicon Macs, install with softwareupdate --install-rosetta
  • Exclude from Spotlight indexing: Excluding development directories like node_modules and .venv from Spotlight indexing improves performance
  • Keychain integration: Registering SSH and GPG keys in macOS Keychain eliminates repeated password prompts
  • Environment variable priority: Loaded in order /etc/paths -> .zprofile -> .zshrc, so check this order when resolving PATH conflicts

Was this article helpful?