keepcalculator

06 Numbers and Powers

Self-Host Code Server as a Cloud IDE on a VPS

Card No. 06·15422 · Updated · Standard formula, shown below

This guide walks you through installing and configuring code-server on your own VPS, turning it into a private, browser-based cloud IDE. You’ll be able to access your projects from any device with a web browser, with your code and extensions stored on your server. You’ll need a VPS with at least 1 GB of RAM, a domain name (or a willingness to use an IP address), and basic comfort with the command line.

What You’ll Need

  • A VPS running Ubuntu 22.04 or 24.04 (other Linux distros work but commands differ)
  • SSH access to the VPS (root or a user with sudo privileges)
  • A domain name pointing to your VPS’s IP (recommended for HTTPS)
  • Open ports 80 and 443 (for HTTP/HTTPS) and 22 (SSH) in your firewall

Step-by-Step

  1. Connect to your VPS via SSH: ssh user@your_server_ip
  2. Update the system: sudo apt update && sudo apt upgrade -y
  3. Download and install code-server using the official install script: curl -fsSL https://code-server.dev/install.sh | sh. This installs the latest version and creates a systemd service.
  4. Enable and start the service: sudo systemctl enable --now code-server@$USER (replace $USER with your actual username, e.g., code-server@ubuntu).
  5. Check the service status: sudo systemctl status code-server@$USER – it should be active and running.
  6. Configure the bind address: edit the config file at ~/.config/code-server/config.yaml. Change bind-addr to 0.0.0.0:8080 (or keep 127.0.0.1 if you’ll use a reverse proxy). Set a strong password in the password field. Save and restart: sudo systemctl restart code-server@$USER.
  7. Set up a reverse proxy with Nginx (recommended for HTTPS and a clean URL). Install Nginx: sudo apt install nginx -y. Create a new site config: sudo nano /etc/nginx/sites-available/code-server. Add a server block that proxies requests to http://localhost:8080. Include WebSocket headers (Upgrade and Connection). Example config below.
  8. Enable the site and test: sudo ln -s /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled/, then sudo nginx -t and sudo systemctl reload nginx.
  9. Obtain an SSL certificate with Let’s Encrypt: sudo apt install certbot python3-certbot-nginx -y, then sudo certbot --nginx -d yourdomain.com. Follow the prompts to get a free certificate and auto-renewal.
  10. Access your IDE: open https://yourdomain.com in a browser, accept the self-signed warning if you skipped HTTPS, and log in with the password you set.

Example Nginx config (replace yourdomain.com):

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Accept-Encoding gzip;
    }
}

Common Mistakes

  • Forgetting to open the firewall port – if you can’t connect, check that port 8080 (or 80/443) is allowed in your VPS’s firewall (ufw or cloud provider security group).
  • Not enabling the systemd service – code-server won’t start on boot unless you run systemctl enable.
  • Using the wrong user in the service name – the service is tied to the user you run it as. If you install as root but start with @ubuntu, it fails.
  • Missing WebSocket headers in Nginx – the terminal and some extensions break without the Upgrade/Connection headers.
  • Leaving the default password – always change it in the config file.

Tips

  • Use a subdomain like ide.yourdomain.com to keep things tidy.
  • Set up a swap file if your VPS has less than 2 GB RAM to avoid out-of-memory crashes.
  • Back up your ~/.local/share/code-server directory regularly – it contains your extensions and settings.
  • Enable auto-updates by running the install script periodically, or set up a cron job.
  • For better security, consider adding basic auth in Nginx in addition to code-server’s password.

Troubleshooting

  • Can’t connect to the web interface – Check if code-server is listening: ss -tlnp | grep 8080. If not, check the service logs: journalctl -u code-server@$USER -f.
  • 502 Bad Gateway from Nginx – Usually means Nginx can’t reach code-server. Verify it’s running on 8080 and the proxy_pass URL matches.
  • Terminal not working in the browser – Ensure the Upgrade and Connection headers are set in the Nginx config, and that you reloaded Nginx.
  • SSL certificate fails – Make sure your domain resolves to the VPS IP before running certbot. Also check that port 80 is open.
  • Code-server starts but stops immediately – Check the logs for permission errors. The service runs as your user, so the config file must be readable by that user.
  • Slow performance – Close unused extensions, increase VPS RAM, or enable gzip in Nginx for static assets.

Frequently Asked Questions

Can I use code-server without a domain name?

Yes, you can access it via http://your_server_ip:8080, but you’ll get a self-signed certificate warning if you try HTTPS. For personal use, that’s fine, but for security, a domain is recommended.

How do I update code-server?

Re-run the install script: curl -fsSL https://code-server.dev/install.sh | sh. It will replace the binary and keep your config. Then restart the service.

Can I run multiple users on one VPS?

Yes, you can run a separate instance per user, each on a different port, but that requires more RAM. Alternatively, use code-server’s multi-user mode with a reverse proxy and authentication, but it’s more complex.

Is it safe to expose code-server to the internet?

With a strong password and HTTPS, it’s reasonably safe for personal use. For production, consider adding fail2ban, using a VPN, or restricting access by IP.

What if I don’t want to use Nginx?

You can run code-server directly on port 443 with SSL, but that requires manual certificate management. Nginx simplifies HTTPS and adds a layer of security.

Can I access my local files from the cloud IDE?

Code-server runs on the VPS, so it only sees files on the VPS. You can sync files using git, or mount a remote drive, but it’s not a direct bridge to your local machine.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →