Install and Set Up Claude Code (2026)

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.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

Claude Code is an npm package. Installation takes about 2 minutes on any platform that has Node.js. Here's the complete setup guide.

Prerequisites

# 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

# 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

Set your API key

# 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-...

First run

# 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-specific setup

# 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

Mac-specific setup

# 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

Troubleshooting

# "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.

Frequently asked questions

How do I install Claude Code?
Install Node.js 18+, then run: npm install -g @anthropic-ai/claude-code. Set your API key: export ANTHROPIC_API_KEY=sk-ant-your-key. Run claude in any project directory.
What does Claude Code cost?
Claude Code itself is free to install. You pay for API usage at standard Anthropic rates. A typical day of development usage costs $1–10 depending on the model and how much code you read/write. Claude Sonnet 4.6 is the recommended model for best cost/quality balance.
Does Claude Code work without an internet connection?
No. Claude Code calls the Anthropic API for every inference — it requires an internet connection. There is no local/offline mode.
How do I update Claude Code?
Run: npm update -g @anthropic-ai/claude-code. Claude Code also shows an update notification in the UI when a new version is available.
Why does Claude Code say 'authentication failed'?
Your ANTHROPIC_API_KEY is missing, expired, or incorrect. Check: echo $ANTHROPIC_API_KEY (must start with sk-ant-). Generate a new key at console.anthropic.com → Settings → API Keys.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript