code-server is a powerful open-source tool that enables you to run Visual Studio Code (VS Code) as a web-based application. With code-server, you can create a cloud-based integrated development environment (IDE), making it accessible from anywhere with an internet connection.
Package | Version | License |
---|---|---|
code-server | 4.19.1 | MIT |
Nginx | 1.18 | Custom |
Certbot | 1.21.0 | Apache 2.0 |
Click the Deploy to DigitalOcean button to create a Droplet based on this 1-Click App. If you aren’t logged in, this link will prompt you to log in with your DigitalOcean account.
In addition to creating a Droplet from the VS Code Server 1-Click App using the control panel, you can also use the DigitalOcean API. As an example, to create a 4GB VS Code Server Droplet in the SFO2 region, you can use the following curl
command. You need to either save your API access token) to an environment variable or substitute it in the command below.
curl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$TOKEN'' -d \
'{"name":"choose_a_name","region":"sfo2","size":"s-2vcpu-4gb","image": "codertechnologie-vscodeserver"}' \
"https://api.digitalocean.com/v2/droplets"
Once the droplet has been created, following are some steps to help you get started with VS Code Server.
Access Your Droplet:
SSH into Your Droplet:
ssh root@your_droplet_ip
Replace your_droplet_ip
with the actual IP address of your Droplet.
* Copy the login credentials for code-server
your_droplet_ip
and login using the password copied in the previous step.Obtain SSL Certificate:
sudo certbot --nginx -d your_domain.com
* Follow the prompts to configure your domain and enable HTTPS.
Auto-Renewal:
sudo certbot renew --dry-run
Configure Nginx:
sudo nano /etc/nginx/sites-available/code-server
* Paste the following configuration:
server {
listen 80;
server_name your_domain.com;<pre> `location / {
proxy_pass http://localhost:8080;
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;
}
# SSL Configuration
listen 443 ssl; # Enable SSL on port 443
ssl_certificate /etc/letsencrypt/live/your_domain.com/fullchain.pem; # Adjust the path
ssl_certificate_key /etc/letsencrypt/live/your_domain.com/privkey.pem; # Adjust the path
include /etc/nginx/snippets/ssl-params.conf; # Include SSL parameters`</pre> }
* Save and exit the editor.
Enable the Nginx Configuration:
sudo ln -s /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled
Test Nginx Configuration:
sudo nginx -t
* If no errors, restart Nginx:
sudo systemctl restart nginx
Access VS Code Server:
https://your_domain.com
.Log In:
Explore VS Code Server:
Customize VS Code Server:
Persistence (Optional):
Replace your_domain.com
with your actual domain throughout the guide.
In this section, you’ll use some of the features of the code-server interface. Since code-server is Visual Studio Code running in the cloud, it has the same interface as the standalone desktop edition.
On the left-hand side of the IDE, there is a vertical row of six buttons that will the most commonly used features in a side panel known as the Activity Bar:
This bar is customizable so you can move these buttons or remove them from the bar. By default, the first button (the hamburger menu icon) opens the general menu in a dropdown, while the second button (the folder icon) opens the Explorer panel that provides tree-like navigation of the project’s structure. You can manage your folders and files here, creating, deleting, moving, and renaming them as necessary. The magnifying glass button provides access to a search and replace functionality.
Following this, in the default order, is the icon that provides your view of the source control systems, like Git. Visual Studio Code also supports other source control providers.
The debugger option (the triangle with a little bug icon) provides common actions for debugging in the panel. Visual Studio Code comes with built-in support for the Node.js runtime debugger and any language that transpiles to Javascript. For other languages, you can install extensions for the required debugger. The four blocks button, which is the final view in the Activity Bar, provides a menu to access available extensions on the VSCode Marketplace.
The primary area of the GUI is your editor, which you can separate by tabs for code editing. You can change your editing view to a grid system or to side-by-side files.
Open code-server.your-domain/?folder=/var/lib/code-server/User
in your browser, which will load an existing folder.
Select the hamburger menu icon to open a menu of options, then select the File menu where you will create a New File. Name the file and save it to the default folder location.
Once saved, the file will be viewable in the Explorer side panel. Creating folders can be done by right-clicking on the Explorer sidebar and clicking on New Folder. You can expand a folder by clicking on its name as well as dragging and dropping files and folders to upper parts of the hierarchy to move them to a new location.
You can gain access to a terminal by clicking on Terminal in the upper menu dropdown, and selecting New Terminal. You can also use the keyboard shortcut listed in the menu. The terminal will open in a lower panel and its working directory will be set to the project’s workspace, which contains the files and folders shown in the Explorer side panel.
In this step, you reviewed the code-server interface and some of the most commonly used features.
You now have code-server, a versatile cloud IDE, installed on your Ubuntu 22.04 server, exposed at your domain, and secured using Let’s Encrypt certificates. You can now work on projects individually or collaboratively as a team. Running a cloud IDE frees resources on your local machine and allows you to scale the resources when needed. For further information, see the Visual Studio Code documentation for additional features and detailed instructions on other components of code-server.