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.

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.
- Prerequisites and Supported Releases
- Step 1: Installing Node.js and npm on Ubuntu
- Step 2: Installing Git and Build Essentials
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.
Complete step-by-step developer tutorial on how to install, configure, and use Claude Code—Anthropic's agentic command-line interface tool—on Ubuntu 24.04 LTS (Noble Numbat) and Linux. Explains installing prerequisite Node.js 18+ and npm runtimes, installing the @anthropic-ai/claude-code package globally, configuring Anthropic API credentials, approving terminal permissions, executing coding and refactoring tasks, and managing updates.
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.0or newer andnpminstalled.- An active Anthropic API account with API credits or a Claude Pro subscription.
- Access to a command-line terminal shell with
gitinstalled.
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.
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:
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.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install Node.js and npm on Ubuntu 24.04 — Set up enterprise-grade Node.js runtimes and package managers on Ubuntu.
- How to Install Git on Ubuntu 24.04 LTS — Configure Git version control and generate SSH authentication keys.
- Initial Server Setup on Ubuntu 24.04 LTS — Foundational baseline setup for Ubuntu developer workstations.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/exit or press Ctrl+C in the terminal to terminate the active Claude Code interactive session.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
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.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides




Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!