Developing locally with VSCode on Windows Subsystem for Linux(WSL)
Before the pandemic, I had a remote VPS box that I’d log into for some random coding work. The benefit of doing so is that it’s always stateful as it never shuts down and rarely reboots, and I could easily pick up from exactly where I left off last time. I primarily use Vim and it’s been great. Since the virus happened and shelter-in-place took effect, I started exploring working from my home computer to take advantage of the many editing/debugging tool options out there, and I scribbled my home development setup as well.
Back then, after some meddling, I realized I couldn’t get a perfect remote development environment, and I decided that VScode/Vim on Mac with everything being local seemed to work best for me. It’s inconvenient though, as I have a Windows PC with a 24-inch monitor that I really wanted to use. The closest I could get to was VSCode + WSL(Windows Subsystem for Linux) but couldn’t get the debugging working for Golang somehow as I remember? I also attempted to let VSCode read from remote via SSH and that didn’t work either(or it’d mess up with my remote dev setup can’t remember exactly). Anyway, I stopped trying at a certain point as the time investment was getting high.
Two months have passed, and things seem to have progressed as well — now that WSL2 is out and it’s said debugging should just work. Hence my 2nd undertaking:
First, upgrade your WSL from 1 to 2. Use the following to verify it’s has been correctly done:
> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
Next, check out your code in WSL, and make sure it could run locally.
Finally, start VSCode by typing:
Simple as that. After installing some required components automatically, you should now have everything ready to be worked on. Debugging also worked for me this time! For further details of developing with VSCode + WSL, this article from the VSCode team helped explain things a lot.