Skip to main content

Installing Claude Code on Any Platform

2/40
Chapter 1 Getting Started with Claude Code

Installing Claude Code on Any Platform

15 min read Lesson 2 / 40 Preview

Prerequisites

Before installing Claude Code, ensure your system meets these minimum requirements:

  • Operating System: macOS 10.15+, Ubuntu 20.04+ / Debian 10+, or Windows with WSL2
  • Node.js: Version 18 or later (Claude Code is distributed as an npm package)
  • RAM: 4 GB minimum (8 GB recommended for large projects)
  • Terminal: Any modern terminal emulator (iTerm2, Alacritty, Windows Terminal, Kitty)

You can verify your Node.js version with:

node --version
# Should output v18.x.x or later

If you need to install or update Node.js, use a version manager like nvm for the smoothest experience:

# Install nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Install the latest LTS version of Node.js
nvm install --lts
nvm use --lts

Installing on macOS

On macOS, you have two installation methods. The recommended approach uses npm directly:

# Method 1: Install globally via npm (recommended)
npm install -g @anthropic-ai/claude-code

# Method 2: Install via Homebrew
brew install claude-code

After installation, verify it works:

claude --version
# Expected output: claude-code v1.x.x

If you are using macOS and encounter permission errors with global npm installs, fix your npm prefix:

# Fix npm global permissions (one-time setup)
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

# Now install Claude Code
npm install -g @anthropic-ai/claude-code

Installing on Linux (Ubuntu/Debian)

The installation process on Linux is nearly identical:

# Ensure Node.js 18+ is installed
node --version

# Install Claude Code globally
npm install -g @anthropic-ai/claude-code

# Verify the installation
claude --version

For Linux distributions that use older Node.js packages in their default repositories, always use nvm or the NodeSource repository to get a current version:

# NodeSource method for Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# Then install Claude Code
npm install -g @anthropic-ai/claude-code

Installing on Windows (WSL2)

Claude Code does not run natively on Windows. You must use Windows Subsystem for Linux 2 (WSL2), which provides a full Linux environment:

# Step 1: Install WSL2 from PowerShell (as Administrator)
wsl --install

# Step 2: Restart your computer, then open Ubuntu from Start menu

# Step 3: Inside WSL2, install Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
nvm install --lts

# Step 4: Install Claude Code
npm install -g @anthropic-ai/claude-code

# Step 5: Verify
claude --version

Important: Always run Claude Code from within your WSL2 terminal, not from PowerShell or Command Prompt. Your project files should ideally live within the WSL2 filesystem (e.g., ~/projects/) for best performance.

Authentication Setup

After installation, you need to authenticate Claude Code with an API provider. Claude Code supports three authentication methods:

Method 1: Anthropic API Key (Direct)

This is the simplest method for individual developers:

# Start Claude Code — it will prompt for authentication on first run
claude

# Or set the API key as an environment variable
export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"

# Add to your shell profile for persistence
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"' >> ~/.zshrc

Method 2: Claude Teams / Enterprise (OAuth)

If your organization uses Claude Teams or Claude Enterprise:

# Launch Claude Code and select "Claude Teams" at the auth prompt
claude

# Follow the browser-based OAuth flow
# Your credentials are cached securely after first login

Method 3: AWS Bedrock

For organizations routing through AWS Bedrock:

# Set the required environment variables
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"

# Start Claude Code
claude

Method 4: Google Vertex AI

For teams using Google Cloud's Vertex AI:

# Set the required environment variables
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=us-east5
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project-id

# Authenticate with Google Cloud
gcloud auth application-default login

# Start Claude Code
claude

Troubleshooting Common Issues

Problem Solution
command not found: claude Ensure the npm global bin is in your PATH
EACCES permission denied Fix npm prefix or use nvm instead of system Node
Authentication fails Check API key validity at console.anthropic.com
Slow on Windows Use WSL2 filesystem, not /mnt/c/ paths
Node version too old Use nvm to install Node.js 18+
# Diagnostic commands for troubleshooting
which claude              # Check if claude is in PATH
npm list -g --depth=0     # Verify global installation
echo $ANTHROPIC_API_KEY   # Check if API key is set (careful with logging)
claude --version          # Confirm installed version

Updating Claude Code

Claude Code receives frequent updates with new features and model improvements. Keep it current:

# Update to the latest version
npm update -g @anthropic-ai/claude-code

# Or with Homebrew on macOS
brew upgrade claude-code

Key Takeaways

  • Claude Code installs via npm (npm install -g @anthropic-ai/claude-code) and requires Node.js 18 or later
  • On Windows, you must use WSL2 — there is no native Windows support
  • Authentication supports four methods: direct API key, Claude Teams OAuth, AWS Bedrock, and Google Vertex AI
  • Always verify your installation with claude --version before starting your first session
  • Use nvm to manage Node.js versions and avoid permission issues with global npm packages