Skip to content

Instantly share code, notes, and snippets.

@mingyc
Last active February 22, 2024 13:12
Show Gist options
  • Save mingyc/803fcbbe1a2286abc231e538f06bfa7c to your computer and use it in GitHub Desktop.
Save mingyc/803fcbbe1a2286abc231e538f06bfa7c to your computer and use it in GitHub Desktop.
[WSL] Setting up a local version of VSCode for the Web

[WSL] Setting up a local version of VSCode for the Web

code serve-web is a locally hosted version of Visual Studio Code for the Web (Note that it's different from VSCode Server). To run it within a WSL such that it can be accessed via the Windows host's browser:

  1. Install VSCode on the WSL distrbution via official download page. For example, download and install the .deb files on Debian WSL:
    sudo apt install ./code_xxxx.deb
    
  2. Enable WSL to run crontab on startup 1 (systemd is by default not available in WSL 2):
    echo '[boot]\ncommand="service cron start"' | sudo tee -a /etc/wsl.conf > /dev/null
    
  3. Add the command into crontab:
    crontab -e
    @reboot DONT_PROMPT_WSL_INSTALL=1 /usr/bin/code serve-web --host 127.0.0.1 --port 59005 --without-connection-token
    
  4. Restart WSL:
    wsl.exe --shutdown
    
  5. Now open the browser on Windows host, and access http://127.0.0.1:59005.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment