Website Vidya
Cloud & DevOpsStep-by-Step Guide

How to Install Claude Code on Ubuntu and Linux: Setup Guide

Learn how to install claude code on ubuntu and Linux via Node.js npm, set up Anthropic API authentication, configure terminal tools, and run agent workflows.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install Claude Code on Ubuntu and Linux: Setup Guide
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install claude code on ubuntu and Linux via Node.js npm, set up Anthropic API authentication, configure terminal tools, and run agent workflows.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Node.js and npm on Ubuntu
  • Step 2: Installing Git and Build Essentials
Grounded in full engineering runbookWebsiteVidya AI Engine

Artificial Intelligence coding assistants have evolved beyond simple editor autocomplete plugins into fully autonomous, terminal-native agentic programming tools.

Claude Code—developed by Anthropic—is an agentic CLI tool that operates directly inside your terminal, understanding your codebase architecture, editing files across directories, executing test suites, running Git commands, and resolving complex bugs interactively.

Because Claude Code operates natively on the Linux command line, it integrates seamlessly into Ubuntu development workstations, cloud VPS servers, and remote SSH coding sessions.

In this guide, we walk through how to install claude code on ubuntu and Linux step-by-step, set up Node.js runtimes, authenticate your Anthropic API credentials, and initiate agentic coding workflows.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A computer or server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • Node.js 18.0 or newer and npm installed.
  • An active Anthropic API account with API credits or a Claude Pro subscription.
  • Access to a command-line terminal shell with git installed.

Step 1: Installing Node.js and npm on Ubuntu

Claude Code is distributed as an npm package and requires Node.js version 18.0 or newer.

Advertisement

While Ubuntu 24.04 includes Node.js 18.x in its default repositories, installing the latest Node.js LTS release via the official NodeSource repository ensures compatibility with modern CLI tools.

Install NodeSource repository and Node.js LTS:

# Update repository cache and install prerequisites:
sudo apt update && sudo apt install -y ca-certificates curl gnupg

# Configure NodeSource repository for Node.js 20 LTS:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

# Install Node.js and npm:
sudo apt install -y nodejs

# Verify installed Node.js and npm versions:
node -v
# Expected output: v20.x or higher
npm -v
# Expected output: 10.x or higher

Step 2: Installing Git and Build Essentials

Claude Code relies heavily on Git to inspect branch history, stage files, review diffs, and create commits during agentic coding sessions.

Verify that git and standard build tools are present on your machine:

Advertisement

If Git is missing, install it using the APT package manager:

# Install Git and essential development packages:
sudo apt update
sudo apt install -y git build-essential

# Confirm Git is operational:
git --version

Step 3: Installing Claude Code via npm Globally

Install the official @anthropic-ai/claude-code package globally using npm.

To avoid npm permission errors when installing global packages without sudo, configure an unprivileged npm prefix or run the global install command:

Execute the installation command in your terminal:

# Configure custom global npm prefix to avoid sudo requirements (recommended):
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'

# Add npm global binaries to your shell PATH in ~/.bashrc:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# Install Claude Code globally:
npm install -g @anthropic-ai/claude-code

# Verify Claude Code CLI installation:
claude --version

Step 4: Authenticating Claude Code with Anthropic API

Claude Code requires authentication with Anthropic's model servers to process natural language queries and generate code changes.

Launch the CLI for the first time by executing claude in your project repository directory:

The interactive setup wizard opens your default web browser to authorize the application or prompts you to input your Anthropic API key:

# Navigate to your project directory:
cd ~/my-project

# Launch Claude Code authentication wizard:
claude

# If prompted for manual API key entry, export your key in ~/.bashrc:
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.bashrc
source ~/.bashrc

Step 5: Executing Agentic Coding Workflows with Claude Code

Claude Code operates as an interactive conversational partner inside your terminal shell.

You can ask questions about your codebase architecture, request new features, ask for unit tests, or instruct Claude to diagnose and fix test failures.

The CLI provides built-in slash commands such as /cost to monitor token usage, /compact to summarize conversation context, and /doctor to diagnose tool configurations.

Before Claude executes commands or modifies files, it displays a concise plan and requests your explicit confirmation:

# Start an interactive Claude Code session in the current directory:
claude

# Example prompt inside Claude session:
# > Explain the authentication flow in src/auth.ts and list potential security gaps.

# Example command execution:
# > Add unit tests for the user registration endpoint using Vitest and run the test suite.

# Non-interactive single-command execution:
claude -p "Refactor calculateTotal() in src/billing.ts to handle edge case null values."

Step 6: Updating and Maintaining Claude Code

Anthropic releases frequent updates and feature enhancements to Claude Code.

To keep your CLI tool updated to the newest version, run npm's global update command:

Running regular updates ensures your local development machine receives the latest agent features, prompt optimizations, and security patches.

You can verify the latest installed version at any time:

# Upgrade Claude Code to the latest release:
npm update -g @anthropic-ai/claude-code

# View current version details:
claude --version

# Check available CLI options and commands:
claude --help

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

npm ERR! code EACCES syscall access '/usr/local/lib/node_modules'

Cause: Attempting to install global npm packages without administrative permissions or custom prefix.

Resolution: Configure a local npm prefix using npm config set prefix '~/.npm-global' and export PATH in ~/.bashrc.

mkdir -p ~/.npm-global && npm config set prefix '~/.npm-global' && echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && source ~/.bashrc

claude: command not found after npm install -g

Cause: The global npm binary directory is not included in your active shell's $PATH variable.

Resolution: Add $(npm config get prefix)/bin to your $PATH in ~/.bashrc and reload.

echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc

Error: Invalid API key or credit balance exhausted

Cause: The provided Anthropic API key is invalid or your developer account lacks billing credits.

Resolution: Verify your API key and billing balance at console.anthropic.com.

echo $ANTHROPIC_API_KEY

Security Best Practices and Hardening

Never store plaintext Anthropic API keys in public Git repositories; always use environment variables or secret files excluded by .gitignore.

Carefully review file diffs and bash commands suggested by Claude Code before approving execution, especially when operating on production servers.

Use sandboxed test environments or Git branches when asking Claude Code to execute multi-file refactoring operations.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
The Claude Code CLI client runs locally on your Ubuntu machine, reading files and executing terminal commands in your local workspace. However, code reasoning, natural language comprehension, and suggestions are processed remotely by Anthropic's Claude 3.5 Sonnet and Opus models via API calls.
Yes. Claude Code operates entirely within text terminals, making it ideal for remote SSH sessions on cloud VPS instances or Docker containers.
Claude Code requires standard read/write permissions for files within your project workspace. It will ask for your confirmation before writing changes or executing terminal bash commands.
Type /exit or press Ctrl+C in the terminal to terminate the active Claude Code interactive session.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Cloud & DevOps•

How to Close File Descriptors Above 9 in Dash Shell

Attempting to close a file descriptor above 9 in Dash using exec 10<&- results in a 10: not found error because Dash's POSIX lexer only recognizes single-digit file descriptors (0–9) in redirection operators. This guide explains the exact parser limitation, why FDs 10+ are reserved for internal shell state, and how to safely close inherited file descriptors using close_range, Python, or Perl wrappers.

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout