Step-by-step guide to installing Claude Code on Mac, Windows, and Linux. Includes API key setup, first run, and common installation problems with fixes.
Claude Code is an npm package. Installation takes about 2 minutes on any platform that has Node.js. Here's the complete setup guide.
# Node.js 18 or higher required:
node --version # must be >= 18
# If you need Node.js:
# Mac: brew install node
# Windows: winget install OpenJS.NodeJS.LTS
# Linux (Ubuntu/Debian): sudo apt install nodejs npm
# Or use: https://nodejs.org/en/download/ (LTS)
# An Anthropic API key (free to generate, usage-based pricing):
# https://console.anthropic.com → Settings → API Keys → Create Key
# Install globally:
npm install -g @anthropic-ai/claude-code
# Verify:
claude --version
# claude-code/x.y.z linux-x64 node-v22.x.x
# If "command not found": your npm global bin isn't on PATH.
# Find it: npm bin -g
# Add to PATH: echo 'export PATH="$(npm bin -g):$PATH"' >> ~/.bashrc
# Option A: environment variable (session only)
export ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
# Option B: persist in shell profile (recommended)
echo 'export ANTHROPIC_API_KEY=sk-ant-api03-your-key-here' >> ~/.bashrc
source ~/.bashrc # or restart terminal
# Option C: .env file in project root (requires dotenv or similar)
# Claude Code does NOT auto-load .env — you must source it manually
# or use a tool like direnv: https://direnv.net
# Verify:
echo $ANTHROPIC_API_KEY # should print sk-ant-...
# Navigate to any project:
cd ~/projects/my-app
# Start Claude Code:
claude
# You'll see the interactive prompt. Type to begin:
> What files are in this project?
# Claude Code reads your directory and responds.
# On first run in a project, it may suggest running /init to create CLAUDE.md.
# One-shot (non-interactive) mode:
claude --print "Summarize this codebase in 5 bullet points"
# Windows: use PowerShell or Windows Terminal
# WSL2 is recommended for best experience (Claude Code is Linux-native)
# Set API key in PowerShell:
$env:ANTHROPIC_API_KEY = "sk-ant-..."
# Persist in PowerShell profile:
echo '$env:ANTHROPIC_API_KEY = "sk-ant-..."' >> $PROFILE
# Or set via System Properties → Environment Variables (GUI)
# WSL2 (recommended):
# Install WSL2, then follow Linux instructions above
wsl --install # enable WSL2
# Then inside WSL: npm install -g @anthropic-ai/claude-code
# macOS Sonoma / Sequoia — no special setup needed
npm install -g @anthropic-ai/claude-code
# If you see "EACCES permission denied":
# Fix npm global permissions:
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
npm install -g @anthropic-ai/claude-code
# Verify Node.js version (Homebrew users may have Node 16):
node --version # must be 18+
brew upgrade node # upgrade if needed
# "authentication failed" or "invalid api key":
echo $ANTHROPIC_API_KEY # must start with sk-ant-
claude --doctor # diagnostic check
# → Get a new key: console.anthropic.com → API Keys
# "claude: command not found" after npm install:
npm bin -g # shows where npm installed the binary
echo $PATH # check if that dir is on PATH
# "EACCES permission denied" on Linux:
# Don't use sudo with npm. Fix ownership:
sudo chown -R $(whoami) ~/.npm
npm install -g @anthropic-ai/claude-code
# Rate limit errors ("429 Too Many Requests"):
# You've hit Anthropic API rate limits. Wait 1 minute, or upgrade your usage tier.
# Tier 1: default. Tier 2+: visit console.anthropic.com → Limits to upgrade.
# Update to latest version:
npm update -g @anthropic-ai/claude-code
After installation, run /init in your project to set up CLAUDE.md. See Claude Code memory guide for what to put in it. For a full command reference, see Claude Code slash commands.