Pre Requisites
- nodejs (version 16 or greater)
- yarn
Always update your Pi first.
sudo apt update
sudo apt full-upgrade
We will use npm (bundled with nodejs) to install yarn because at the time of writing it has proved problematic to use npm to install code-server.
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm -g install yarn
Install code-server
yarn global add code-server
Create Initial Config File And Edit It
~/.yarn/bin/code-server
Kill the program with ctrl-c and then edit the config file.
nano ~/.config/code-server/config.yaml
Change the bind-addr to allow access from all bound network addresses and set your password. Also set cert to true and cert-host to your Pi’s hostname (with .local appended) which will create a certificate for you in ~/.local/share/code-server
named <your hostname>_local.crt
and .key
. You can replace these files if you have a non local domain for your Pi.
bind-addr: 0.0.0.0:8080
auth: password
password: <YOUR PASSWORD>
cert: true
cert-host: <YOUR HOSTNAME>.local
Set The code-server to start automatically
Firstly create the service file.
sudo nano /etc/systemd/system/code-server.service
Add the following contents – replace <YOUR USER ID> with your Pi username (pi by default or use the command `whoami`).
[Unit]
Description=code-server
After=network.target
[Service]
User=<YOUR USER ID>
Group=<YOUR USER ID>
WorkingDirectory=/home/<YOUR USER ID>
Environment="PATH=/usr/bin"
ExecStart=/home/<YOUR USER ID>/.yarn/bin/code-server
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Once the file is saved set code-server to run on startup and start the server manually.
sudo systemctl enable code-server
sudo systemctl start code-server
Test Your Server
Either use your Raspberry Pi’s local address or IP address on port 8080 to connect to your instance:
https://raspi.local:8080
Now you should see yourself in a browser instance of Visual Studio Code.
You may also see some errors regarding the secure certificate. At this point you will need to copy the certificate you created above onto your browser device and install it. The process for this will depend on what device you are using.
The process for adding one to your iPad is outlined here.
Leave a Reply