Chapter 2
Installation & Setup, Step by Step
In this chapter we'll install Claude Code and connect it to your account. It usually takes 5 to 10 minutes, and in most cases a single command is enough.
Step 1: Open a terminal
The terminal is a window where you type commands to the computer instead of clicking buttons. Each operating system opens it a little differently:
- Click the Start button (or press the Windows key).
- Type
PowerShell. - Click Windows PowerShell in the results.
The line will start with something like PS C:\Users\YourName>. The letters PS tell you you're in PowerShell.
- Click the Start button (or press the Windows key).
- Type
cmd. - Click Command Prompt.
The line will start with something like C:\Users\YourName>, without the letters PS.
On Mac: press Cmd + Space, type Terminal and press Enter.
On Linux (e.g. Ubuntu): press Ctrl + Alt + T, or search for Terminal in the app menu.
Step 2: Install Claude Code
Copy the right command (there's a Copy button in the corner of the box), paste it into the terminal and press Enter:
irm https://claude.ai/install.ps1 | iexcurl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmdcurl -fsSL https://claude.ai/install.sh | bashOther install methods (optional)
If you already use a package manager, you can install through it too. Note: with this kind of install Claude Code doesn't update itself, and you'll need to update it manually from time to time.
winget install Anthropic.ClaudeCodewinget install Anthropic.ClaudeCodebrew install --cask claude-codeStep 3: Check that the install worked
Close the terminal window and open a new one. This matters: the old window doesn't "know" new software was installed. In the new window, type:
claude --versionIf all is well, you'll see a version number, for example:
2.1.211 (Claude Code)Your number will probably be different, and that's fine. It just shows the install worked.
For a more thorough check, there's a built-in diagnostic command. It checks the install and settings and suggests fixes if something is off:
claude doctorStep 4: Sign in to your account
There are two main ways to pay for Claude Code. The difference is mostly how you pay:
| Claude subscription (Pro / Max) | Claude Console account (API key) | |
|---|---|---|
| How you pay | A fixed monthly price | By usage, from prepaid credit |
| Good for | Most people, especially beginners | Developers, businesses, and anyone who wants precise cost control |
| Upside | No surprise bills, and you get Claude on the web and apps too | You only pay for what you use |
| Downside | There's a usage limit per period | Heavy use can get expensive |
Option A: Sign in with a Claude subscription (recommended)
-
In the terminal, type
claudeand press Enter:Terminalclaude -
The first time, Claude Code asks a few setup questions, for example which color theme you prefer. Choose with the arrow keys and press Enter.
-
When asked to choose a sign-in method, pick the Claude account (subscription) option.
-
A browser window opens. Sign in to your Claude account and approve access.
-
Go back to the terminal. When
Login successfulappears, press Enter, and that's it: you're signed in.
Option B: Sign in with Claude Console (pay as you go)
- Go to platform.claude.com, create an account and add credit.
- In the terminal, type
claude. - Choose the Anthropic Console option and sign in through the browser. You can sign in with the account itself, without creating an API key at all.
Advanced: using an existing API key
If you already have an API key from the Console, you can store it in an environment variable called ANTHROPIC_API_KEY. The next time you run claude, it asks whether to use the key, and once you approve, it skips the browser sign-in.
$env:ANTHROPIC_API_KEY = "sk-ant-..."set ANTHROPIC_API_KEY=sk-ant-...export ANTHROPIC_API_KEY="sk-ant-..."Replace sk-ant-... with your real key.
Switching accounts and signing out
Your sign-in is saved on the computer, so you don't need to sign in every time. To switch accounts, type inside Claude Code:
/logout
/loginUpdates
The official install (the command from step 2) updates itself in the background, so you don't need to do anything. If you want to update right away anyway:
claude updateIf you installed with WinGet or Homebrew, updating is manual:
winget upgrade Anthropic.ClaudeCodewinget upgrade Anthropic.ClaudeCodebrew upgrade claude-codeTroubleshooting
Something didn't work? Don't worry, almost every install problem is one of these.
"claude: command not found" or "'claude' is not recognized"
What happened: the install succeeded, but the folder Claude Code was installed into isn't on your PATH. The PATH is the list of folders your computer searches for programs when you type a command name. If the folder isn't on the list, the computer simply can't find claude.
First: make sure you closed the terminal and opened a new window. If the terminal is inside a code editor like Cursor or VS Code, close the whole editor and open it again.
If that didn't help, add the folder to your PATH:
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')Then close the terminal, open a new one and try claude --version again.
The fix is easiest through PowerShell. Open PowerShell (see step 1) and run:
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')Then close all terminal windows, open a new CMD and try claude --version again.
On Mac (zsh shell, the default):
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcOn Linux (bash shell, the default on most distributions):
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcThe first line saves the setting for every future window, and the second applies it to the current one. If you're not sure which shell you're in, type echo $SHELL.
"'irm' is not recognized" or "The token '&&' is not a valid statement separator"
What happened: the command you copied is meant for a different kind of terminal.
irmis not recognized: you're in CMD but ran the PowerShell command. Switch to the Windows CMD tab in step 2, or open PowerShell.&&is not a valid statement separator: you're in PowerShell but ran the CMD command. Switch to the Windows PowerShell tab.A parameter cannot be found that matches parameter name 'fsSL'or'bash' is not recognized: you ran the Mac/Linux command on Windows. Use the PowerShell command.
"running scripts is disabled on this system" (PowerShell execution policy)
What happened: PowerShell has a security feature called the execution policy that blocks running script files. This error does not appear with the official install from step 2. It shows up mainly if you installed Claude Code through npm, the Node.js package manager.
There are three ways to fix it, most recommended first:
- Reinstall the official way with the PowerShell command from step 2. It isn't affected by the policy.
- Run
claude.cmdinstead ofclaude. It's the same program, and the policy doesn't apply to it. - Allow local scripts for your user only:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserThe install fails with a different error
syntax error near unexpected token '<'or403: a web page arrived instead of the installer, usually because of a network problem, a VPN or a blocked workplace network. Try another network, or use WinGet or Homebrew.App unavailable in region: Claude Code isn't available in the country you're connecting from. List of supported countries.
Sign-in problems
- The browser doesn't open: press
cin the terminal to copy the link, and paste it into your browser. - You signed in to the wrong account: type
/logoutand then/logininside Claude Code. - A message says you don't have access: make sure you have a paid plan. The free Claude plan doesn't include Claude Code.
Summary
- We installed Claude Code with one command, and checked it with
claude --version. - We signed in: a Claude subscription (recommended for beginners) or a Console account.
- We learned to fix the common problems: PATH, the wrong terminal type, and the execution policy.
In the next chapter we'll start Claude Code for the first time and ask it to build something real.
Check yourself
1. You installed, but you see 'claude is not recognized'. What's most likely?
2. You have a Pro subscription and an API key you approved. Which will Claude Code use?
Answering every quiz question marks the chapter as done automatically.