Skip to content

Claude Code Installation Guide

Follow this tutorial to easily install and use Claude Code on your computer.

📍 Choose Your Operating System

🪟 Windows Installation Tutorial

1 Install Node.js Environment

Claude Code requires a Node.js environment to run.

Method 1: Official Download (Recommended)

  1. Visit Node.js Official Website
  2. Click "LTS" version to download
  3. Double-click the .msi file and follow the installation wizard
  4. Verify installation:
bash
node --version && npm --version

Method 2: Using Package Manager

powershell
# Using Chocolatey
choco install nodejs

# Using Scoop
scoop install nodejs

Verify successful installation

  • After installation, open PowerShell or CMD and enter the following commands:
powershell
node --version
npm --version

If version numbers are displayed, installation was successful!

2 Install Claude Code

Method 1: PowerShell One-Click Installation (Recommended)

powershell
# Run PowerShell as administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
irm https://anthropic.com/claude-code/install.ps1 | iex

Method 2: npm Installation

powershell
npm install -g @anthropic/claude-code

3 Set Environment Variables

Configure Claude Code environment variables

To allow Claude Code to connect to your proxy service, you need to set two environment variables:

Method 1: PowerShell Temporary Setting (Current Session)

Run the following commands in PowerShell:

powershell
$env:ANTHROPIC_BASE_URL = "your-url"
$env:ANTHROPIC_AUTH_TOKEN = "your-API-key"

💡 Remember to replace "your-API-key" with the actual key you created in the "API Keys" tab above.

Method 2: PowerShell Permanent Setting (User-level)

Run the following commands in PowerShell to set user-level environment variables:

powershell
# Set user-level environment variables (permanent)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "your-url", [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "your-API-key", [System.EnvironmentVariableTarget]::User)

View set environment variables:

powershell
# View user-level environment variables
[System.Environment]::GetEnvironmentVariable("ANTHROPIC_BASE_URL", [System.EnvironmentVariableTarget]::User)
[System.Environment]::GetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", [System.EnvironmentVariableTarget]::User)

💡 You need to restart PowerShell window for the settings to take effect.

Verify Environment Variable Settings

After setting environment variables, you can verify if they were set successfully with the following commands:

Verify in PowerShell:

powershell
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKEN

Verify in CMD:

cmd
echo %ANTHROPIC_BASE_URL%
echo %ANTHROPIC_AUTH_TOKEN%

Expected output example:

your-url
cr_xxxxxxxxxxxxxxxxxx

💡 If output is empty or shows the variable name itself, environment variable setting failed, please set again.

4 Start Using Claude Code

Now you can start using Claude Code!

Launch Claude Code

powershell
claude

Use in Specific Project

powershell
# Navigate to your project directory
cd C:\path\to\your\project
# Launch Claude Code
claude

5 Troubleshooting Common Issues

Issue: "permission denied" error during installation

  • This is usually a permission issue, try the following solutions:
  • Run PowerShell as administrator
  • Or configure npm to use user directory: npm config set prefix %APPDATA%\npm

Issue: claude-code command not found

  • Restart PowerShell
  • Check if installed as administrator

Issue: PowerShell execution policy error

  • If you encounter execution policy restrictions, run:
powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

🍎 macOS Installation Tutorial

1 Install Node.js Environment

Claude Code requires a Node.js environment to run.

macOS Installation Methods

Method 1: Using Homebrew (Recommended)

If you already have Homebrew installed, using it to install Node.js is more convenient:

bash
# Update Homebrew
brew update
# Install Node.js
brew install node

Method 2: Official Website Download

  1. Visit https://nodejs.org/
  2. Download the LTS version for macOS
  3. Open the downloaded .pkg file
  4. Follow the installation program instructions to complete installation

macOS Notes

  • If you encounter permission issues, you may need to use sudo
  • First run may require permission in System Preferences
  • Recommend using Terminal or iTerm2

Verify successful installation

After installation, open Terminal and enter the following commands:

bash
node --version
npm --version

If version numbers are displayed, installation was successful!

2 Install Claude Code

Install Claude Code

Open Terminal and run the following command:

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

If you encounter permission issues, you can use sudo:

bash
sudo npm install -g @anthropic-ai/claude-code

Verify Claude Code Installation

After installation, enter the following command to check if installation was successful:

bash
claude --version

If version number is displayed, congratulations! Claude Code has been successfully installed.

3 Set Environment Variables

Configure Claude Code Environment Variables

To allow Claude Code to connect to your proxy service, you need to set two environment variables:

Method 1: Temporary Setting (Current Session)

Run the following commands in Terminal:

bash
export ANTHROPIC_BASE_URL="your-url"
export ANTHROPIC_AUTH_TOKEN="your-API-key"

💡 Remember to replace "your-API-key" with the actual key you created in the "API Keys" tab above.

Method 2: Permanent Setting

Edit your shell configuration file (depending on your shell):

bash
# For zsh (default)
echo 'export ANTHROPIC_BASE_URL="your-url"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="your-API-key"' >> ~/.zshrc
source ~/.zshrc
bash
# For bash
echo 'export ANTHROPIC_BASE_URL="your-url"' >> ~/.bash_profile
echo 'export ANTHROPIC_AUTH_TOKEN="your-API-key"' >> ~/.bash_profile
source ~/.bash_profile

4 Start Using Claude Code

Now you can start using Claude Code!

Launch Claude Code

bash
claude

Use in Specific Project

bash
# Navigate to your project directory
cd /path/to/your/project
# Launch Claude Code
claude

5 Troubleshooting Common Issues

Issue: Permission errors

bash
# Configure npm permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc

Issue: macOS security settings blocking execution

  • If system blocks Claude Code execution:
    • Open "System Preferences" → "Security & Privacy"
    • Click "Open Anyway" or "Allow"
    • Or run in Terminal: sudo spctl --master-disable

Issue: Environment variables not taking effect

  • Check the following:
    • Confirm you modified the correct configuration file (.zshrc or .bash_profile)
    • Restart Terminal
    • Verify settings: echo $ANTHROPIC_BASE_URL

🐧 Linux/WSL2 Installation Tutorial

1 Install Node.js Environment

Claude Code requires a Node.js environment to run.

Linux Installation Methods

Method 1: Using Official Repository (Recommended)

bash
# Add NodeSource repository
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
# Install Node.js
sudo apt-get install -y nodejs

Method 2: Using System Package Manager

While version may not be the latest, it's sufficient for basic use:

bash
# Ubuntu/Debian
sudo apt update
sudo apt install nodejs npm

# CentOS/RHEL/Fedora
sudo dnf install nodejs npm

Linux Notes

  • Some distributions may need additional dependencies
  • If you encounter permission issues, use sudo
  • Ensure your user has write permissions to npm global directory

Verify successful installation

After installation, open terminal and enter the following commands:

bash
node --version
npm --version

If version numbers are displayed, installation was successful!

2 Install Claude Code

Install Claude Code

Open terminal and run the following command:

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

If you encounter permission issues, you can use sudo:

bash
sudo npm install -g @anthropic-ai/claude-code

Verify Claude Code Installation

After installation, enter the following command to check if installation was successful:

bash
claude --version

If version number is displayed, congratulations! Claude Code has been successfully installed.

3 Set Environment Variables

Configure Claude Code Environment Variables

To allow Claude Code to connect to your proxy service, you need to set two environment variables:

Method 1: Temporary Setting (Current Session)

Run the following commands in terminal:

bash
export ANTHROPIC_BASE_URL="your-url"
export ANTHROPIC_AUTH_TOKEN="your-API-key"

💡 Remember to replace "your-API-key" with the actual key you created in the "API Keys" tab above.

Method 2: Permanent Setting

Edit your shell configuration file:

bash
# For bash (default)
echo 'export ANTHROPIC_BASE_URL="your-url"' >> ~/.bashrc
echo 'export ANTHROPIC_AUTH_TOKEN="your-API-key"' >> ~/.bashrc
source ~/.bashrc
bash
# For zsh
echo 'export ANTHROPIC_BASE_URL="your-url"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="your-API-key"' >> ~/.zshrc
source ~/.zshrc

4 Start Using Claude Code

Now you can start using Claude Code!

Launch Claude Code

bash
claude

Use in Specific Project

bash
# Navigate to your project directory
cd /path/to/your/project
# Launch Claude Code
claude

5 Troubleshooting Common Issues

Issue: Permission error during installation

  • Try the following solutions:
    • Use sudo for installation: sudo npm install -g @anthropic-ai/claude-code
    • Or configure npm to use user directory: npm config set prefix ~/.npm-global
    • Then add to PATH: export PATH=~/.npm-global/bin:$PATH

Issue: Missing dependency libraries

  • Some Linux distributions need additional dependencies:
bash
# Ubuntu/Debian
sudo apt install build-essential
# CentOS/RHEL
sudo dnf groupinstall "Development Tools"

Issue: Environment variables not taking effect

  • Check the following:
    • Confirm you modified the correct configuration file (.bashrc or .zshrc)
    • Restart terminal or run source ~/.bashrc
    • Verify settings: echo $ANTHROPIC_BASE_URL

💡 More Help

Start your AI programming journey! 🎉

Claude Relay Service - Self-hosted Claude API relay service, secure and efficient