This guide walks you through installing Claude Code, Anthropic’s command-line coding agent, on Linux. It covers the official install methods, initial setup, and common fixes. By the end, you’ll be able to run claude from your terminal and start using it in your projects.
What You’ll Need
- A Linux distribution (Ubuntu, Debian, Fedora, Arch, etc.) with a 64-bit architecture
- A terminal emulator (GNOME Terminal, Konsole, or any terminal you prefer)
- Node.js version 18 or newer (required for the npm install method)
- An Anthropic account with access to Claude Code (you’ll need to authenticate during setup)
- An internet connection for downloading packages and authenticating
Step-by-Step
-
Check your Node.js version (if using npm)
Open your terminal and runnode -v. If Node.js is not installed or is older than version 18, install it first. On Ubuntu/Debian, you can usesudo apt update && sudo apt install nodejs npm. For other distros, use your package manager or install Node.js via nvm (Node Version Manager) for easier updates. -
Install Claude Code globally via npm
Run the following command in your terminal:
sudo npm install -g @anthropic-ai/claude-code
If you don’t have sudo privileges, you can install it without sudo by configuring npm’s global prefix to a directory you own (see Tips below). -
Verify the installation
After the install completes, runclaude --versionto confirm it’s installed. You should see a version number like1.0.0(or newer). If you get a “command not found” error, your npm global bin directory may not be in your PATH (see Troubleshooting). -
Authenticate with Anthropic
Runclaudein your terminal. On first launch, it will prompt you to authenticate. You’ll be given a link to open in your browser to log in to your Anthropic account and authorize the CLI. After authorizing, copy the code from the terminal and paste it into the browser page. The terminal will confirm you’re logged in. -
Test Claude Code in a project
Navigate to a directory where you want to use Claude Code (e.g.,cd ~/my-project), then runclaude. It should start an interactive session. Try a simple prompt like “What files are in this directory?” to verify it’s working. -
Update Claude Code when needed
To update to the latest version, runsudo npm update -g @anthropic-ai/claude-codeor simply re-run the install command. Claude Code also checks for updates automatically and will notify you if a new version is available.
Common Mistakes
- Using an outdated Node.js version: Claude Code requires Node 18+. If you have an older version, the install may fail or the CLI may crash. Always check with
node -vfirst. - Installing without sudo when you need it: If you don’t have write permissions to the global npm directory, the install will fail with an EACCES error. Either use sudo or configure npm to use a user-owned directory.
- Not adding npm’s global bin to PATH: If you can’t run
claudeafter installation, it’s often because npm’s global bin directory (e.g.,/usr/local/binor~/.npm-global/bin) isn’t in your PATH environment variable. - Skipping the authentication step: Some users think the install is broken when they see a login prompt. That’s normal; you must authenticate once to use Claude Code.
- Running Claude Code in a directory without permissions: If you’re in a system directory like
/etc, Claude Code may not be able to read or write files. Use it in your own project directories.
Tips
- Install without sudo for a cleaner setup: Create a user-level npm directory to avoid permission issues. Run:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Then addexport PATH=~/.npm-global/bin:$PATHto your shell profile (e.g.,~/.bashrcor~/.zshrc), and source it withsource ~/.bashrc. Then install without sudo:npm install -g @anthropic-ai/claude-code. - Use nvm for Node.js management: If you work on multiple projects with different Node versions, nvm makes it easy to switch. Install nvm, then
nvm install 18(or later) andnvm use 18. - Set up a shell alias: If you find yourself typing
claudeoften, you can set an alias likealias cc='claude'in your shell profile for speed. - Keep your API key handy: If you’re using an API key instead of OAuth, you can set the
ANTHROPIC_API_KEYenvironment variable. However, the OAuth flow is recommended for most users. - Check for updates regularly: Claude Code is under active development. Running
claude --versionand comparing it to the latest release notes on the official repository can help you stay current.
Troubleshooting
- “command not found” after install: This means npm’s global bin directory is not in your PATH. Check where npm installs globally with
npm prefix -g. Then add that directory to your PATH (e.g.,export PATH="$(npm prefix -g)/bin:$PATH"in your shell profile). - EACCES permission errors during install: This happens when npm tries to write to a system directory you don’t own. Use
sudo npm install -g, or better, configure a user-level prefix as described in Tips. - Node.js version too old: If you get a syntax error when running
claude, it’s likely your Node version is too old. Update Node.js to version 18 or newer. On Ubuntu, you can usesudo apt install nodejsbut this may not give you the latest. Using nvm is more reliable. - Authentication fails: If the OAuth flow fails, try restarting the terminal and running
claudeagain. Ensure you’re logged into the correct Anthropic account in your browser. If you’re behind a corporate firewall, you may need to set proxy environment variables. - Claude Code crashes on startup: Check your Node.js version and make sure it’s supported. Also, try clearing the cache with
claude --clear-cache(if available) or reinstalling the package. - Network issues during install: If npm install fails due to network, try setting a mirror or registry:
npm config set registry https://registry.npmjs.org. If you’re in a restricted network, you might need a proxy.
Frequently Asked Questions
Do I need an Anthropic API key to use Claude Code?
You need an Anthropic account and must authenticate. The easiest way is the OAuth flow during first launch. You can also use an API key by setting the ANTHROPIC_API_KEY environment variable, but OAuth is simpler for most users.
Can I install Claude Code without sudo?
Yes. Configure npm to use a user-owned directory (as shown in Tips) and then install without sudo. This is recommended to avoid permission issues.
Is Claude Code free?
Claude Code uses your Anthropic API usage, which may incur costs depending on your plan. Check Anthropic’s pricing page for details. There is no separate charge for the CLI tool itself.
How do I update Claude Code?
Run sudo npm update -g @anthropic-ai/claude-code or reinstall the package. The CLI also notifies you when an update is available.
Can I use Claude Code with other AI models?
Claude Code is specifically designed for Anthropic’s Claude models. It doesn’t support other models out of the box.
Does Claude Code work on WSL (Windows Subsystem for Linux)?
Yes, it works in WSL2 as long as you have a supported Linux distribution and Node.js installed inside WSL. The installation steps are the same.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Disable Autocorrect on iPhone or iPad: Quick Guide
- Custom Keyboard Shortcuts on Windows 11 & macOS
- Restore Windows 11 Display Scaling to Recommended
- Semiconductor Cycle: How Investors Track It0.0
- Microsoft Store Error 0x80073d12: Fixes That Work
- View Notification Count on iPhone: Full Guide