Tutorial

How To Set Up the code-server Cloud IDE Platform on Ubuntu 18.04 [Quickstart]

Published on January 3, 2020
English
How To Set Up the code-server Cloud IDE Platform on Ubuntu 18.04 [Quickstart]

Introduction

code-server is Microsoft Visual Studio Code running on a remote server and accessible directly from your browser. This means that you can use various devices, running different operating systems, and always have a consistent development environment on hand.

In this tutorial, you will set up the code-server cloud IDE platform on your Ubuntu 18.04 machine and expose it at your domain, secured with Let’s Encrypt. For a more detailed version of this tutorial, please refer to How To Set Up the code-server Cloud IDE Platform on Ubuntu 18.04.

Prerequisites

  • A server running Ubuntu 18.04 with at least 2GB of RAM, root access, and a sudo, non-root account. You can set this up by following the Initial Server Setup Guide for Ubuntu 18.04.

  • Nginx installed on your server. For a guide on how to do this, complete Steps 1 to 4 of How To Install Nginx on Ubuntu 18.04.

  • A fully registered domain name to host code-server, pointed to your server. This tutorial will use code-server.your-domain throughout. You can purchase a domain name on Namecheap, get one for free on Freenom, or use the domain registrar of your choice.

  • Both of the following DNS records set up for your server. You can follow this introduction to DigitalOcean DNS for details on how to add them.

    • An A record with your-domain pointing to your server’s public IP address.
    • An A record with www.your-domain pointing to your server’s public IP address.

Step 1 — Installing code-server

Create the directory to store all data for code-server:

  1. mkdir ~/code-server

Navigate to it:

  1. cd ~/code-server

Visit the Github releases page of code-server and pick the latest Linux build. Download it using:

  1. wget https://github.com/cdr/code-server/releases/download/2.1692-vsc1.39.2/code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz

Unpack the archive:

  1. tar -xzvf code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz

Navigate to the directory containing the code-server executable:

  1. cd code-server2.1692-vsc1.39.2-linux-x86_64

To access the code-server executable across your system, copy it with:

  1. sudo cp code-server /usr/local/bin

Create a folder for code-server to store user data:

  1. sudo mkdir /var/lib/code-server

Create a systemd service, code-server.service, in the /lib/systemd/system directory:

  1. sudo nano /lib/systemd/system/code-server.service

Add the following lines:

/lib/systemd/system/code-server.service
[Unit]
Description=code-server
After=nginx.service

[Service]
Type=simple
Environment=PASSWORD=your_password
ExecStart=/usr/local/bin/code-server --host 127.0.0.1 --user-data-dir /var/lib/code-server --auth password
Restart=always

[Install]
WantedBy=multi-user.target
  • --host 127.0.0.1 binds it to localhost.
  • --user-data-dir /var/lib/code-server sets its user data directory.
  • --auth password specifies that it should authenticate visitors with a password.

Remember to replace your_password with your desired password.

Save and close the file.

Start the code-server service:

  1. sudo systemctl start code-server

Check that it’s started correctly:

  1. sudo systemctl status code-server

You’ll see output similar to:

Output
● code-server.service - code-server Loaded: loaded (/lib/systemd/system/code-server.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2019-12-09 20:07:28 UTC; 4s ago Main PID: 5216 (code-server) Tasks: 23 (limit: 2362) CGroup: /system.slice/code-server.service ├─5216 /usr/local/bin/code-server --host 127.0.0.1 --user-data-dir /var/lib/code-server --auth password └─5240 /usr/local/bin/code-server --host 127.0.0.1 --user-data-dir /var/lib/code-server --auth password ...

Enable the code-server service to start automatically after a server reboot:

  1. sudo systemctl enable code-server

Step 2 — Exposing code-server

Now you will configure Nginx as a reverse proxy for code-server.

Create code-server.conf to store the configuration for exposing code-server at your domain:

  1. sudo nano /etc/nginx/sites-available/code-server.conf

Add the following lines to set up your server block with the necessary directives:

/etc/nginx/sites-available/code-server.conf
server {
	listen 80;
	listen [::]:80;

	server_name code-server.your_domain;

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

Replace code-server.your_domain with your desired domain, then save and close the file.

To make this site configuration active, create a symlink of it:

  1. sudo ln -s /etc/nginx/sites-available/code-server.conf /etc/nginx/sites-enabled/code-server.conf

Test the validity of the configuration:

  1. sudo nginx -t

You’ll see the following output:

Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

For the configuration to take effect, restart Nginx:

  1. sudo systemctl restart nginx

Step 3 — Securing Your Domain

Now you’ll secure your domain using a Let’s Encrypt TLS certificate.

Add the Certbot package repository to your server:

  1. sudo add-apt-repository ppa:certbot/certbot

Install Certbot and its Nginx plugin:

  1. sudo apt install python-certbot-nginx

Configure ufw to accept encrypted traffic:

  1. sudo ufw allow https

The output will be:

Output
Rule added Rule added (v6)

Reload it for the configuration to take effect:

  1. sudo ufw reload

The output will show:

Output
Firewall reloaded

Navigate to your code-server domain.

code-server login prompt

Enter your code-server password. You’ll see the interface exposed at your domain.

code-server GUI

To secure it, install a Let’s Encrypt TLS certificate using Certbot.

Request a certificate for your domain with:

  1. sudo certbot --nginx -d code-server.your_domain

Provide an email address for urgent notices, accept the EFF’s Terms of Service, and decide whether to redirect all HTTP traffic to HTTPS.

The output will be similar to this:

Output
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/code-server.your_domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/code-server.your_domain/privkey.pem Your cert will expire on ... To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" ...

Certbot has successfully generated TLS certificates and applied them to the Nginx configuration for your domain.

Conclusion

You now have code-server, a versatile cloud IDE, installed on your Ubuntu 18.04 server, exposed at your domain and secured using Let’s Encrypt certificates. For further information, see the Visual Studio Code documentation for additional features and detailed instructions on other components of code-server.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Savic

author



Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
3 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hey,

Could you please update this guide for the version 3.0.0 update of code-server?

Thanks!

I keep getting “Invalid password” when I try to login to code-server, any ideas?

my website getting this error in every 5 to 10 minutes

This site can’t be reached motivationwishing.com took too long to respond. Try:

Checking the connection Checking the proxy and the firewall Running Windows Network Diagnostics ERR_TIMED_OUT

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.