Installing Claude Code

Claude Code installs in under five minutes on any modern macOS, Linux, or Windows machine. This topic walks through every step, explains what each step does, and covers the common problems that catch beginners off guard.

What You Need Before Installing

 REQUIREMENTS CHECKLIST
 ┌────────────────────────────────────────────────────────┐
 │                                                        │
 │  ✓  Computer: macOS 12+, Linux (Ubuntu/Debian/etc),    │
 │               or Windows 10/11 with WSL2 enabled       │
 │                                                        │
 │  ✓  Node.js: version 18.0.0 or higher                  │
 │     Check: open terminal, type  node --version         │
 │     Need it? Download from nodejs.org                  │
 │                                                        │
 │  ✓  npm: comes with Node.js automatically              │
 │     Check: type  npm --version  in terminal            │
 │                                                        │
 │  ✓  Anthropic account: free at console.anthropic.com   │
 │                                                        │
 │  ✓  Internet connection during install                 │
 │                                                        │
 └────────────────────────────────────────────────────────┘

Checking Your Node.js Version

Open a terminal window and run this command:

node --version

The terminal prints something like v20.11.0. Any number at version 18 or above works fine. If the terminal says command not found, Node.js is not installed on your machine. Visit nodejs.org, download the LTS version, and run the installer before continuing.

Why Node.js Is Required

Claude Code is written in JavaScript and runs on Node.js. Node.js is the engine that makes JavaScript programs run outside a browser. You do not need to know JavaScript to use Claude Code — Node.js is just the vehicle the tool rides in.

Installing Claude Code

Run this single command in your terminal:

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

The -g flag installs Claude Code globally, which means you can run it from any folder on your computer, not just from the folder where you installed it. The installation downloads the tool and sets it up. Depending on your internet speed, it takes between 30 seconds and 2 minutes.

 What npm install -g does (step by step)
 ┌─────────────────────────────────────────────────────────┐
 │                                                         │
 │  npm  →  contacts the npm registry on the internet      │
 │     │                                                   │
 │     ▼                                                   │
 │  downloads @anthropic-ai/claude-code package            │
 │     │                                                   │
 │     ▼                                                   │
 │  installs it in your global Node.js folder              │
 │     │    (something like /usr/local/lib/node_modules)   │
 │     ▼                                                   │
 │  creates a "claude" command in your PATH                │
 │     │    (so typing "claude" anywhere works)            │
 │     ▼                                                   │
 │  Done — claude command is now available system-wide     │
 │                                                         │
 └─────────────────────────────────────────────────────────┘

Fixing Permission Errors on macOS and Linux

Some macOS and Linux setups block global npm installs without elevated permissions. If the install fails with a permission error, run it with sudo:

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

Type your system password when prompted. The password does not display as you type — that is normal. Press Enter when finished.

A better long-term fix is to configure npm to use a folder you own without sudo. The npm documentation at docs.npmjs.com explains how to do this under "Resolving EACCES permissions errors."

Verifying the Installation

After the install finishes, check that the claude command is available:

claude --version

The terminal prints the version number, for example 1.0.17. If the terminal says command not found, the installation did not complete correctly — the troubleshooting section below covers the common causes.

Setting Up Your Anthropic API Key

Claude Code connects to Anthropic's AI model through an API key. Think of the API key as a password that identifies you and links your usage to your Anthropic account.

Getting Your API Key

 How to find your API key
 ┌──────────────────────────────────────────────────────┐
 │                                                      │
 │  1. Go to  console.anthropic.com                     │
 │                                                      │
 │  2. Sign in or create a free account                 │
 │                                                      │
 │  3. Click your name in the top-right corner          │
 │                                                      │
 │  4. Select "API Keys" from the dropdown              │
 │                                                      │
 │  5. Click "Create Key"                               │
 │                                                      │
 │  6. Give the key a name (e.g., "my-laptop")          │
 │                                                      │
 │  7. Copy the key — it starts with  sk-ant-api...     │
 │     You see it only once, so copy it now             │
 │                                                      │
 └──────────────────────────────────────────────────────┘

Adding the API Key to Your System

Set the key as an environment variable. On macOS and Linux, add this line to your shell configuration file (~/.zshrc for Zsh, ~/.bashrc for Bash):

export ANTHROPIC_API_KEY="sk-ant-api-your-actual-key-here"

Replace the value with your real key. After adding the line, apply the change:

source ~/.zshrc

Or restart your terminal. On Windows (WSL), edit ~/.bashrc in the same way and run source ~/.bashrc.

Why an Environment Variable

 THREE PLACES TO PUT A SECRET KEY — ONLY ONE IS SAFE
 ┌──────────────────┬────────────────────────────────────┐
 │  In your code    │  DANGEROUS — key ends up in        │
 │  (hardcoded)     │  version control and gets exposed  │
 ├──────────────────┼────────────────────────────────────┤
 │  In a plain      │  RISKY — easy to accidentally      │
 │  text file       │  commit or share the file          │
 ├──────────────────┼────────────────────────────────────┤
 │  Environment     │  SAFE — lives only in your shell,  │
 │  variable        │  never in files you share          │
 └──────────────────┴────────────────────────────────────┘

Environment variables live in your shell's memory during a session. They do not appear in your code files, your project folders, or your Git commits. Keep your API key here and nowhere else.

Running Claude Code for the First Time

Navigate to any project folder and run:

claude

Claude Code opens an interactive session in your terminal. It greets you, shows the current working directory, and waits for your first message. Type something simple to verify everything works:

Hello — are you working correctly?

Claude Code responds with a short greeting. The installation is complete and working.

Common Installation Problems

Problem: "command not found: claude" after installing

 DIAGNOSIS FLOWCHART
 ┌─────────────────────────────────────────────────┐
 │  Did the npm install finish without errors?     │
 │  NO  → re-run  npm install -g @anthropic-ai/    │
 │              claude-code  and watch for errors  │
 │  YES ↓                                          │
 │  Is the npm global bin folder in your PATH?     │
 │  Check: run  npm bin -g  to find the folder     │
 │  Add that folder to your PATH in ~/.zshrc or    │
 │  ~/.bashrc, then source the file and try again  │
 └─────────────────────────────────────────────────┘

Problem: "Invalid API key" error when starting Claude Code

The environment variable is either missing or has a typo. Run echo $ANTHROPIC_API_KEY in your terminal. If it prints nothing, the variable is not set. If it prints a key, compare it character by character with the key in your Anthropic console.

Problem: Install fails with ETIMEDOUT or network errors

Check your internet connection. If you are behind a corporate proxy or VPN, the proxy may be blocking npm. Ask your network administrator for the proxy settings and configure npm to use them with npm config set proxy.

Keeping Claude Code Updated

Anthropic releases updates regularly. Update Claude Code with the same command you used to install it:

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

Running this again replaces the old version with the latest one. Check the current version at any time with claude --version.

Key Points

  • Claude Code requires Node.js version 18 or higher — check with node --version before installing.
  • Install with one command: npm install -g @anthropic-ai/claude-code
  • Store your Anthropic API key in an environment variable, never in a code file.
  • Verify the install with claude --version, then launch with claude from any project folder.
  • Update with the same install command whenever Anthropic releases a new version.

Leave a Comment