Installing Claude Code
This guide will walk you through installing Claude Code on your platform of choice.
Prerequisites
- Node.js 18.0 or higher
- npm or yarn package manager
- An Anthropic account or API key
Platform-Specific Installation
- macOS
- Windows (WSL2)
- Linux
macOS Installation
-
Install Node.js (if not already installed):
# Using Homebrew
brew install node
# Or download from nodejs.org -
Install Claude Code globally:
npm install -g @anthropic-ai/claude-code -
Verify installation:
claude --version -
Launch Claude Code:
claudeOn first launch, Claude will guide you through connecting your Anthropic account or providing an API key.
If you encounter permission errors, try using sudo or adjust your npm configuration:
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
Windows Installation via WSL2
-
Install WSL2:
# In PowerShell as Administrator
wsl --install -
Set up a Linux distribution (Ubuntu recommended):
wsl --install -d Ubuntu -
Inside WSL2, install Node.js:
# Update package list
sudo apt update
# Install Node.js via NodeSource
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs -
Install Claude Code:
npm install -g @anthropic-ai/claude-code -
Verify installation:
claude --version
To use Claude Code with VS Code on Windows:
- Install the "Remote - WSL" extension
- Open VS Code from WSL:
code . - Run
claudefrom the integrated terminal
Linux Installation
-
Install Node.js:
# Debian/Ubuntu
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
# Fedora/RHEL
sudo dnf install nodejs
# Arch Linux
sudo pacman -S nodejs npm -
Install Claude Code:
npm install -g @anthropic-ai/claude-code -
Verify installation:
claude --version
API Key Setup
Claude needs your Anthropic API key to function. You have several options for configuration:
Option 1: Environment Variable (Recommended)
Add to your shell profile (~/.bashrc, ~/.zshrc, etc.):
export ANTHROPIC_API_KEY="your-api-key-here"
Then reload your shell:
source ~/.bashrc # or ~/.zshrc
Option 2: Settings File
Store in ~/.claude/settings.json:
{
"apiKey": "your-api-key-here"
}
Option 3: Interactive Setup
Simply run claude and follow the prompts to enter your API key interactively.
Troubleshooting
Permission Denied Errors
If you get EACCES errors during installation:
# Create a directory for global packages
mkdir ~/.npm-global
# Configure npm to use the new directory
npm config set prefix '~/.npm-global'
# Add to PATH (add to your shell profile)
export PATH=~/.npm-global/bin:$PATH
# Retry installation
npm install -g @anthropic-ai/claude-code
Command Not Found
If claude command is not found after installation:
-
Check npm's global bin directory:
npm bin -g -
Ensure this directory is in your PATH:
echo $PATH -
Add to PATH if missing (in your shell profile):
export PATH=$(npm bin -g):$PATH
Next Steps
Now that you have Claude Code installed, proceed to Your First Project to start using it!