...
πŸš€ deploy claude code on ubuntu vps
Learn how to deploy claude code on ubuntu vps!

This article demonstrates how to deploy Claude Code on Ubuntu VPS.

What is Claude Code?

Claude Code refers to using Claude (Anthropic’s AI model family) as a development assistant for writing, reviewing, refactoring, and reasoning about code β€” typically through an API-driven backend, CLI tool, IDE integration, or internal tooling layer. It is powered by models developed by Anthropic.

What Claude Code Can Do

When integrated into a VPS, IDE, or internal system, it can:

  • Generate production-ready code
  • Refactor legacy codebases
  • Explain complex scripts or logs
  • Create infrastructure configs (Docker, systemd, Nginx, etc.)
  • Write tests and documentation
  • Debug stack traces
  • Assist with DevOps automation
  • Convert code between languages

How It’s Typically Used

Claude Code isn’t a standalone product by default. It is usually deployed as:

  1. API-backed internal assistant
    A Node/Python backend that sends prompts to Claude and returns responses.
  2. CLI tool
    A terminal-based assistant for server-side development.
  3. IDE integration
    Similar in workflow to tools like:

    • GitHub Copilot
    • Cursor
  4. Secure self-hosted relay
    A VPS-hosted gateway that protects API keys and manages usage.

Models Commonly Used for Code

Examples include:

  • Claude 3 Opus (advanced reasoning)
  • Claude 3.5 Sonnet (balanced performance)
  • Claude 3 Haiku (fast + lightweight)

All accessible via Anthropic’s API.

In Simple Terms

Claude Code=A programmable AI coding assistant you can deploy inside your own infrastructure.

Launch 100% ssd ubuntu vps from $3. 19/mo!


Compare Ubuntu VPS Plans

KVM-SSD-1
KVM-SSD-8
KVM-SSD-16
KVM-SSD-32
CPU
1 Core
2 Cores
4 Cores
8 Cores
Memory
1 GB
8 GB
16 GB
32 GB
Storage
16 GB NVMe
128 GB NVMe
256 GB NVMe
512 GB NVMe
Bandwidth
1 TB
4 TB
8 TB
16 TB
Network
1 Gbps
1 Gbps
1 Gbps
1 Gbps
Delivery Time
⏱️ Instant
⏱️ Instant
⏱️ Instant
⏱️ Instant
Location
US/FR
US/FR
US/FR
US/FR
Price
$7.58*
$39.50*
$79.40*
$151.22*
KVM-SSD-1
CPU: 1 Core
Memory: 2 GB
Storage: 16 GB NVMe
1 TB
KVM-SSD-8
CPU: 2 Cores
Memory: 8 GB
Storage: 128 GB NVMe
4 TB
KVM-SSD-16
CPU: 4 Cores
Memory: 16 GB
Storage: 256 GB NVMe
8 TB
KVM-SSD-32
CPU: 8 Cores
Memory: 32 GB
Storage: 512 GB NVMe
16 TB

How to Deploy Claude Code on Ubuntu VPS

To deploy Claude Code on Ubuntu VPS, follow the steps provided below:

  1. Overview

    This guide walks through deploying Claude Code on a fresh Ubuntu VPS in a secure, production-ready manner, including:

    • OS preparation
    • Node.js installation
    • Claude API configuration
    • Systemd service setup
    • Nginx reverse proxy
    • SSL via Let’s Encrypt
    • Basic hardening
  2. Recommended VPS Specifications

    Minimum:

    If you expect heavy concurrent usage (e.g., internal dev team or API relay), scale to 4 vCPU / 8GB RAM.


    Compare Ubuntu VPS Plans

    KVM-SSD-1
    KVM-SSD-8
    KVM-SSD-16
    KVM-SSD-32
    CPU
    1 Core
    2 Cores
    4 Cores
    8 Cores
    Memory
    1 GB
    8 GB
    16 GB
    32 GB
    Storage
    16 GB NVMe
    128 GB NVMe
    256 GB NVMe
    512 GB NVMe
    Bandwidth
    1 TB
    4 TB
    8 TB
    16 TB
    Network
    1 Gbps
    1 Gbps
    1 Gbps
    1 Gbps
    Delivery Time
    ⏱️ Instant
    ⏱️ Instant
    ⏱️ Instant
    ⏱️ Instant
    Location
    US/FR
    US/FR
    US/FR
    US/FR
    Price
    $7.58*
    $39.50*
    $79.40*
    $151.22*
    KVM-SSD-1
    CPU: 1 Core
    Memory: 2 GB
    Storage: 16 GB NVMe
    1 TB
    KVM-SSD-8
    CPU: 2 Cores
    Memory: 8 GB
    Storage: 128 GB NVMe
    4 TB
    KVM-SSD-16
    CPU: 4 Cores
    Memory: 16 GB
    Storage: 256 GB NVMe
    8 TB
    KVM-SSD-32
    CPU: 8 Cores
    Memory: 32 GB
    Storage: 512 GB NVMe
    16 TB

  3. Initial Server Setup

    1. Update System

      apt update && apt upgrade -y
      
    2. Create a Non-Root User

      adduser claude
      usermod -aG sudo claude
      

      Switch to that user:

      su - claude
      
  4. Install Required Dependencies

    1. Install Node.js (LTS)

      Use NodeSource:

      curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
      sudo apt install -y nodejs
      

      Verify:

      node -v
      npm -v
      
  5. Obtain Claude API Access

    You will need:

    • API key from Anthropic
    • Model name (e.g., claude-3-7-sonnet-latest)

    Register and manage keys via:

    Anthropic

    Store your API key securely.

  6. Create Claude Code Application

    1. Create Project Directory

      mkdir ~/claude-app
      cd ~/claude-app
      
    2. Initialize Project

      npm init -y
      npm install express axios dotenv
      
  7. Create Application Server

    Create server.js:

    import express from "express";
    import axios from "axios";
    import dotenv from "dotenv";
    
    dotenv.config();
    const app = express();
    app.use(express.json());
    
    app.post("/ask", async (req, res) => {
      try {
        const response = await axios.post(
          "https://api.anthropic.com/v1/messages",
          {
            model: "claude-3-7-sonnet-latest",
            max_tokens: 1000,
            messages: [
              { role: "user", content: req.body.prompt }
            ]
          },
          {
            headers: {
              "x-api-key": process.env.CLAUDE_API_KEY,
              "anthropic-version": "2023-06-01",
              "content-type": "application/json"
            }
          }
        );
    
        res.json(response.data);
      } catch (err) {
        res.status(500).json({ error: err.message });
      }
    });
    
    app.listen(3000, () => {
      console.log("Claude app running on port 3000");
    });
    
  8. Environment Configuration

    Create .env file:

    CLAUDE_API_KEY=your_api_key_here
    

    Restrict permissions:

    chmod 600 .env
    
  9. Enable ES Modules

    Edit package.json and add:

    "type": "module"
    
  10. Test Application

    node server.js
    

    Test locally:

    curl -X POST http://localhost:3000/ask \
      -H "Content-Type: application/json" \
      -d '{"prompt":"Explain zero-trust architecture"}'
    
  11. Install Nginx Reverse Proxy

    sudo apt install nginx -y
    

    Create config:

    sudo nano /etc/nginx/sites-available/claude
    

    Example config:

    server {
        listen 80;
        server_name 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;
        }
    }
    

    Enable site:

    sudo ln -s /etc/nginx/sites-available/claude /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl restart nginx
    
  12. Secure with SSL (Let’s Encrypt)

    Install Certbot:

    sudo apt install certbot python3-certbot-nginx -y
    

    Run:

    sudo certbot --nginx -d yourdomain.com
    

    Certificates issued via:

    Let’s Encrypt

    Auto-renewal is installed automatically.

  13. Create Systemd Service

    Create:

    sudo nano /etc/systemd/system/claude.service
    
    [Unit]
    Description=Claude Code App
    After=network.target
    
    [Service]
    User=claude
    WorkingDirectory=/home/claude/claude-app
    ExecStart=/usr/bin/node server.js
    Restart=always
    Environment=NODE_ENV=production
    
    [Install]
    WantedBy=multi-user.target
    

    Enable service:

    sudo systemctl daemon-reload
    sudo systemctl enable claude
    sudo systemctl start claude
    

    Check status:

    sudo systemctl status claude
    
  14. Firewall Configuration

    Enable UFW:

    sudo ufw allow OpenSSH
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    
  15. Optional Production Enhancements

    1. Add Rate Limiting

      Install:

      npm install express-rate-limit
      
    2. Add Logging

      npm install morgan
      
    3. Run with PM2 (Alternative to Systemd)

      sudo npm install -g pm2
      pm2 start server.js
      pm2 startup
      pm2 save
      
  16. Scaling Considerations

    For heavier production workloads:

    • Deploy behind Cloudflare
    • Use Redis caching layer
    • Use horizontal scaling via load balancer
    • Implement request queue to prevent API exhaustion
  17. Security Best Practices

    • Never expose API key client-side
    • Use environment variables only
    • Restrict IP access if internal tool
    • Enable automatic OS security updates
    • Monitor logs via journalctl -u claude
  18. Deployment Complete

    You now have:

    • Ubuntu VPS
    • Node-based Claude backend
    • Reverse proxy
    • SSL encryption
    • Persistent service
    • Firewall enabled

Launch 100% ssd ubuntu vps from $3. 19/mo!

Conclusion

You now know how to deploy Claude Code on Ubuntu VPS.

Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX.
lg