WSL & Windows

How to Install Claude Code CLI on WSL2 Ubuntu

Claude Code is a command-line tool by Anthropic that lets you work with Claude directly from your terminal. You can use it for code…

How to Install Claude Code CLI on WSL2 Ubuntu
Share:

How to Install Claude Code CLI on WSL2 Ubuntu

3 min read
6.2K views

Claude Code is a command-line tool by Anthropic that lets you work with Claude directly from your terminal. You can use it for code reviews, debugging, generating scripts, and working with project files. This guide walks you through installing Claude Code CLI on WSL2 Ubuntu.

WSL2 is the better environment for Claude Code on Windows: it has full Bash support, native Linux paths, and plays nicely with tools like Docker and Terraform. If you’d rather install on PowerShell directly, see How to Install and Configure Claude Code CLI on Windows PowerShell.

Advertisement

Prerequisites

Step 1: Install the Native CLI

Run Anthropic’s recommended native installer inside Ubuntu, without sudo. It does not require Node.js:

curl -fsSL https://claude.ai/install.sh | bash

Step 2: Verify the Installation

Open a new Ubuntu terminal, then check the version and installation health:

claude --version
claude doctor

Optional npm route: use Linux Node.js 22 or later, then run npm install -g @anthropic-ai/claude-code@latest without sudo. Choose one installation method to avoid multiple copies on PATH. The native installer is simpler when Node.js is not otherwise needed.

Step 3: Authenticate

Run claude to start the authentication flow:

claude

Available authentication routes depend on your account and configuration:

  1. Claude account (subscription): uses an eligible Claude subscription, including Pro, Max, Ultra, Team, or Enterprise, subject to plan limits.
  2. Anthropic Console (API billing): uses API credits from your Anthropic account.
  3. Third-party platform: connects through AWS Bedrock, Google Cloud, Microsoft Foundry, or another supported provider; these require provider configuration.

Pick one and follow the browser prompt to log in. WSL2 will open the URL in your Windows default browser. Once you approve, you’re authenticated.

Claude Code CLI running in an Ubuntu WSL2 terminal
Claude CLI installed in Ubuntu WSL2 environment

Basic Usage

Claude Code reads files in your current directory, so cd into your project first. To connect external tools, follow the MCP server configuration guide.

Start an interactive session:

cd ~/projects/my-app
claude

Ask a one-off question with -p (print mode):

claude -p "review this terraform code and suggest improvements"

Pipe output from another command:

cat error.log | claude -p "explain this error and suggest a fix"

Update Claude Code

Native installations update automatically. To check manually, run the command below. For the optional npm route, use npm install -g @anthropic-ai/claude-code@latest; avoid npm update -g.

claude update

Troubleshooting

claude: command not found

For the native install, ensure ~/.local/bin is on PATH. Try this in the current shell, then add it once to ~/.bashrc if needed:

export PATH="$HOME/.local/bin:$PATH"
command -v claude
claude doctor

EACCES permission error during install

Use the native installer without sudo rather than recursively changing ownership of npm directories. If retaining npm, follow Anthropic’s permission troubleshooting and verify it uses Linux Node.js inside WSL.

Slow file performance

If Claude Code feels slow when reading files, make sure your project is in the Linux file system (/home/yourname/) and not on the Windows mount (/mnt/c/). WSL2 file access across the mount boundary is significantly slower.

Security Tips

  • Don’t paste real credentials, API keys, or secrets into prompts.
  • If using API billing, set the key as an environment variable (export ANTHROPIC_API_KEY="your-key" in ~/.bashrc) instead of passing it inline.
  • Review any generated infrastructure code or IAM policies before applying them.

Conclusion

That covers installing Claude Code CLI on WSL2 Ubuntu. The native installer handles the CLI directly; verify it with claude doctor before starting a project.

If you’re also setting up your WSL environment, you might find How to Connect Visual Studio Code with WSL 2 for Linux Ubuntu useful for connecting VS Code to your WSL instance.

Recommended for Linux builders

Contabo VPS hosting for Linux projects

Run Linux servers, automation tools, and self-hosted apps on a Contabo VPS with generous resources and predictable pricing.

Our customers sayExcellent4.6 out of 5 based on 11,008 reviews Trustpilot

Some links are affiliate links. This may earn LinuxBeast a commission at no extra cost to you.

Privacy settings

Choose which privacy controls to open.

Opening these controls does not change your saved choices.