
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:
- API-backed internal assistant
A Node/Python backend that sends prompts to Claude and returns responses. - CLI tool
A terminal-based assistant for server-side development. - IDE integration
Similar in workflow to tools like:- GitHub Copilot
- Cursor
- 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.
Compare Ubuntu VPS Plans
How to Deploy Claude Code on Ubuntu VPS
To deploy Claude Code on Ubuntu VPS, follow the steps provided below:
-
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
-
Recommended VPS Specifications
Minimum:
- 2 vCPU
- 4GB RAM
- 40GB SSD
- Ubuntu 22.04 LTS (recommended) or Ubuntu 24.04 LTS
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-1KVM-SSD-8KVM-SSD-16KVM-SSD-32CPU1 Core2 Cores4 Cores8 CoresMemory1 GB8 GB16 GB32 GBStorage16 GB NVMe128 GB NVMe256 GB NVMe512 GB NVMeBandwidth1 TB4 TB8 TB16 TBNetwork1 Gbps1 Gbps1 Gbps1 GbpsDelivery Timeβ±οΈ Instantβ±οΈ Instantβ±οΈ Instantβ±οΈ InstantLocationUS/FRUS/FRUS/FRUS/FRPrice$7.58*$39.50*$79.40*$151.22*
-
Initial Server Setup
-
Update System
apt update && apt upgrade -y
-
Create a Non-Root User
adduser claude usermod -aG sudo claude
Switch to that user:
su - claude
-
-
Install Required Dependencies
-
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
-
-
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.
-
Create Claude Code Application
-
Create Project Directory
mkdir ~/claude-app cd ~/claude-app
-
Initialize Project
npm init -y npm install express axios dotenv
-
-
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"); }); -
Environment Configuration
Create
.envfile:CLAUDE_API_KEY=your_api_key_here
Restrict permissions:
chmod 600 .env
-
Enable ES Modules
Edit
package.jsonand add:"type": "module"
-
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"}' -
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
-
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.
-
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
-
Firewall Configuration
Enable UFW:
sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw enable
-
Optional Production Enhancements
-
Add Rate Limiting
Install:
npm install express-rate-limit
-
Add Logging
npm install morgan
-
Run with PM2 (Alternative to Systemd)
sudo npm install -g pm2 pm2 start server.js pm2 startup pm2 save
-
-
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
-
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
-
Deployment Complete
You now have:
- Ubuntu VPS
- Node-based Claude backend
- Reverse proxy
- SSL encryption
- Persistent service
- Firewall enabled
Conclusion
You now know how to deploy Claude Code on Ubuntu VPS.









