Native Linux installation with distribution-specific guides. Supports Ubuntu, Debian, Fedora, Arch, openSUSE, and more.
Select your Linux distribution for tailored installation instructions.
20.04 LTS+
11+
35+
Rolling
For experienced users - get Claude Code running in 3 commands
# Install Node.js (Ubuntu/Debian)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install Claude Code
npm install -g @anthropic-ai/claude-code
# Run Claude Code
claude
Other distros: Replace apt commands with your package manager (dnf, pacman, zypper, etc.)
New to Linux package management? Follow our detailed guide with explanations for each command.
Experienced Linux user? Jump to advanced configurations, containerization, and enterprise features.
Claude Code runs natively on most modern Linux distributions.
Kernel Version | Linux 4.15+ (most distributions from 2018+) |
Architecture | x86_64 (AMD64) or ARM64 (aarch64) |
Memory | 2GB RAM minimum (4GB+ recommended) |
Storage | 1GB free space for Node.js and Claude Code |
Network | Internet connection for installation and API access |
Permissions | sudo access for package installation |
Follow these detailed steps to install Claude Code on Linux. Perfect for users new to Linux package management.
First, update your system packages to ensure you have the latest security updates and package information.
# Update package list
sudo apt update
# Upgrade installed packages
sudo apt upgrade -y
# Install essential tools
sudo apt install curl wget gnupg2 software-properties-common -y
# Update system packages
sudo dnf update -y
# Install essential tools
sudo dnf install curl wget gnupg2 -y
# Update system
sudo pacman -Syu
# Install essential tools
sudo pacman -S curl wget gnupg base-devel
# Update system
sudo zypper update -y
# Install essential tools
sudo zypper install curl wget gpg2
Why update first? This ensures you have the latest package information and security updates before installing new software.
Claude Code requires Node.js 18 or higher. We'll install the latest LTS version using the NodeSource repository.
This method provides the latest Node.js versions for Ubuntu/Debian:
# Add NodeSource repository
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# Install Node.js
sudo apt-get install -y nodejs
# Verify installation
node --version
npm --version
# Install Node.js from Fedora repos
sudo dnf install nodejs npm -y
# Install Node.js from Arch repos
sudo pacman -S nodejs npm
For managing multiple Node.js versions:
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Reload shell
source ~/.bashrc
# Install latest LTS Node.js
nvm install --lts
nvm use --lts
# Create directory for global packages
mkdir -p ~/.npm-global
# Configure npm to use this directory
npm config set prefix ~/.npm-global
# Add to PATH
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Verification: You should see Node.js v18+ and npm v8+ when running the version commands.
Now we can install Claude Code using npm. This downloads the latest version from the official repository.
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Verify installation
claude --version
# Check if it's in PATH
which claude
If available on your distribution:
# Install via Snap (if available)
sudo snap install node --classic
sudo snap install claude-code
If you encounter permission issues:
# Fix npm permissions (if needed)
sudo chown -R $(whoami) ~/.npm-global
# Or reinstall with correct permissions
npm config set prefix ~/.npm-global
npm install -g @anthropic-ai/claude-code
Important: Never use sudo npm install -g
as this can cause permission and security issues.
Configure Claude Code to work with your Anthropic account using either Claude Max or an API key.
Best for regular users ($20/month):
claude
# Navigate to your project
cd ~/Projects/your-project
# Start Claude Code
claude
For pay-per-use or enterprise:
# Set API key
export ANTHROPIC_API_KEY=your_key_here
# Add to shell profile
echo 'export ANTHROPIC_API_KEY=your_key' >> ~/.bashrc
source ~/.bashrc
Shell | Config File | Command |
---|---|---|
Bash | ~/.bashrc |
echo 'export ANTHROPIC_API_KEY=key' >> ~/.bashrc |
Zsh | ~/.zshrc |
echo 'export ANTHROPIC_API_KEY=key' >> ~/.zshrc |
Fish | ~/.config/fish/config.fish |
set -Ux ANTHROPIC_API_KEY key |
Tip: Check your default shell with echo $SHELL
to know which config file to use.
Test Claude Code with your first project and learn the basic Linux workflow.
# Create a new project directory
mkdir ~/claude-test
cd ~/claude-test
# Create a simple Python script
cat > hello.py << 'EOF'
#!/usr/bin/env python3
print("Hello Claude from Linux!")
EOF
# Make it executable
chmod +x hello.py
# Create a README
echo "# My First Claude Code Project on Linux" > README.md
# Start Claude Code in your project
claude
# Try some basic commands
> "Explain what this Python script does"
> "/init" # Generate project documentation
> "/help" # See all available commands
> "/doctor" # Check system health
/permissions
- Manage file permissions/status
- Check system status/terminal-setup
- Optimize terminal settings/clear
- Clear conversation context/exit
- Exit Claude CodeSuccess! You've successfully installed Claude Code on Linux. Welcome to AI-powered development on the world's most powerful OS!
Advanced setup for experienced Linux users with server deployment, containerization, and enterprise features.
Automated installation scripts for different Linux distributions.
# Complete installation
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && \
sudo apt-get install -y nodejs && \
mkdir -p ~/.npm-global && \
npm config set prefix ~/.npm-global && \
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && \
source ~/.bashrc && \
npm install -g @anthropic-ai/claude-code
# Complete installation
sudo dnf install -y nodejs npm && \
mkdir -p ~/.npm-global && \
npm config set prefix ~/.npm-global && \
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && \
source ~/.bashrc && \
npm install -g @anthropic-ai/claude-code
# Complete installation
sudo pacman -S nodejs npm && \
mkdir -p ~/.npm-global && \
npm config set prefix ~/.npm-global && \
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && \
source ~/.bashrc && \
npm install -g @anthropic-ai/claude-code
# Install with NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash && \
source ~/.bashrc && \
nvm install --lts && \
nvm use --lts && \
npm install -g @anthropic-ai/claude-code
Containerized Claude Code for development, CI/CD, and production environments.
# Dockerfile for Claude Code
FROM node:20-alpine
# Install system dependencies
RUN apk add --no-cache git curl bash
# Create non-root user
RUN addgroup -g 1001 -S claude && \
adduser -S claude -u 1001 -G claude
# Set working directory
WORKDIR /workspace
# Install Claude Code
RUN npm install -g @anthropic-ai/claude-code
# Switch to non-root user
USER claude
# Set environment variables
ENV ANTHROPIC_API_KEY=""
ENV NODE_OPTIONS="--max-old-space-size=4096"
# Default command
CMD ["claude"]
# docker-compose.yml
version: '3.8'
services:
claude-code:
build: .
volumes:
- ./:/workspace
- ~/.claude.json:/home/claude/.claude.json:ro
environment:
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
stdin_open: true
tty: true
working_dir: /workspace
# Build and run interactively
docker build -t claude-code .
docker run -it --rm -v $(pwd):/workspace -e ANTHROPIC_API_KEY=your_key claude-code
# Run with Docker Compose
docker-compose run --rm claude-code
# Automated mode for CI/CD
docker run --rm -v $(pwd):/workspace -e ANTHROPIC_API_KEY=your_key claude-code \
claude --dangerously-skip-permissions -p "run tests and fix any issues"
Deploy Claude Code on Linux servers for team access and automation.
Create /etc/systemd/system/claude-code.service
:
[Unit]
Description=Claude Code Service
After=network.target
[Service]
Type=simple
User=claude
WorkingDirectory=/opt/claude-workspace
Environment=ANTHROPIC_API_KEY=your_key
Environment=NODE_OPTIONS=--max-old-space-size=8192
ExecStart=/usr/local/bin/claude --headless
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
# Enable and start service
sudo systemctl enable claude-code
sudo systemctl start claude-code
sudo systemctl status claude-code
For web-based access:
# /etc/nginx/sites-available/claude-code
server {
listen 80;
server_name claude.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
Enterprise-grade configurations for production environments.
Create /etc/claude/config.json
:
{
"defaultModel": "claude-sonnet-4",
"permissions": {
"allowedTools": ["Edit", "Bash(git*)"],
"deniedTools": ["Bash(rm*)", "Bash(sudo*)"]
},
"preferences": {
"autoCompact": true,
"compactThreshold": 100000,
"maxMemoryUsage": "8GB"
},
"logging": {
"level": "info",
"file": "/var/log/claude-code.log"
},
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/opt/projects"]
}
}
}
Add to /etc/environment
:
# System-wide environment variables
ANTHROPIC_API_KEY=your_key
CLAUDE_MODEL=claude-sonnet-4
NODE_OPTIONS=--max-old-space-size=8192
MCP_DEBUG=false
# Performance tuning
UV_THREADPOOL_SIZE=16
NODE_ENV=production
# Security hardening
# Create dedicated user
sudo useradd -r -s /bin/bash -d /opt/claude claude
sudo mkdir -p /opt/claude/{workspace,logs}
sudo chown -R claude:claude /opt/claude
# Set up log rotation
sudo tee /etc/logrotate.d/claude-code << 'EOF'
/var/log/claude-code.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 claude claude
}
EOF
Integrate Claude Code into your continuous integration and deployment pipelines.
# .github/workflows/claude-review.yml
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Review PR
run: |
claude --dangerously-skip-permissions \
-p "Review this PR for code quality, security, and best practices"
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# .gitlab-ci.yml
stages:
- review
- test
claude-review:
stage: review
image: node:20-alpine
before_script:
- apk add --no-cache git
- npm install -g @anthropic-ai/claude-code
script:
- claude --dangerously-skip-permissions
-p "Analyze code changes and suggest improvements"
variables:
ANTHROPIC_API_KEY: $ANTHROPIC_API_KEY
only:
- merge_requests
// Jenkinsfile
pipeline {
agent any
environment {
ANTHROPIC_API_KEY = credentials('anthropic-api-key')
}
stages {
stage('Setup') {
steps {
sh 'npm install -g @anthropic-ai/claude-code'
}
}
stage('Code Review') {
steps {
sh '''
claude --dangerously-skip-permissions \
-p "Review code changes for quality and security issues"
'''
}
}
stage('Generate Documentation') {
steps {
sh 'claude -p "Update project documentation based on code changes"'
}
}
}
}
Solutions to common issues specific to Linux distributions and environments.
# Ubuntu/Debian: Add NodeSource repo
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Fedora: Enable NodeJS module
sudo dnf module enable nodejs:20
sudo dnf install nodejs npm
# Fix npm global directory permissions
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Ubuntu/Debian
sudo apt install build-essential
# Fedora
sudo dnf groupinstall "Development Tools"
# Arch
sudo pacman -S base-devel
# Check if installed
npm list -g @anthropic-ai/claude-code
# Check PATH
echo $PATH | grep npm
# Add to PATH if missing
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=8192"
# Add to shell profile
echo 'export NODE_OPTIONS="--max-old-space-size=8192"' >> ~/.bashrc
# Check system memory
free -h
# Test API connectivity
curl -I https://api.anthropic.com
# Check DNS resolution
nslookup api.anthropic.com
# Test with different DNS
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Check SELinux status
sestatus
# Temporarily disable (if needed)
sudo setenforce 0
# Create SELinux policy for Claude Code
sudo setsebool -P httpd_can_network_connect 1
# Check AppArmor status
sudo aa-status
# If needed, create profile exception
sudo aa-complain /usr/bin/node
# If using snap-installed Node.js
sudo snap refresh node
# Or switch to system Node.js
sudo snap remove node
# Then install via package manager
# Use tmpfs for temporary files
sudo mount -t tmpfs -o size=2G tmpfs /tmp
# Add to /etc/fstab for persistence
echo "tmpfs /tmp tmpfs size=2G 0 0" | sudo tee -a /etc/fstab
# Increase file descriptor limits
echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
# Check current limits
ulimit -n
# Set CPU governor to performance
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Check CPU info
lscpu | grep -E "Model name|CPU\(s\)|Thread"
Excellent! You've successfully installed Claude Code on Linux. Here's what to explore next:
Need help? Check our troubleshooting guide or visit the community resources.