Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Visual Studio Code on WSL2?

I want to use Visual Studio Code already installed on Windows for WSL2 (I use ubuntu app on Microsoft Store). When I cd into the directory to use and type code . then show an error message

To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the code command in a WSL terminal just as you would in a normal command prompt.

I have installed Remote - WSL plugin on Visual Studio Code and it works but can't open Visual Studio Code on ubuntu app.

like image 331
quoc9x Avatar asked Oct 15 '25 07:10

quoc9x


2 Answers

I solved my problem, the cause is same as in messeage:

To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the code command in a WSL terminal just as you would in a normal command prompt.

I installed extra Visual Studio Code on ubuntu app (this is not necessary) so when i type code . the system will understand that I'm using Visual Studio Code already installed on ubuntu app I uninstall Visual Studio Code on ubuntu app by

sudo dpkg --purge code
rm -rf ~/.vscode

Note: make sure that the default of wsl is now ubuntu app, otherwise use the following command:

wsl -s Ubuntu-20.04   

enter image description here

Then I typed code . on ubuntu app it actually opened Visual Studio Code on Windows for me.

enter image description here

Thanks for Watching!

like image 189
quoc9x Avatar answered Oct 16 '25 23:10

quoc9x


If you've just installed vscode in Windows, you'll likely need to logout/in before the environment changes will be picked up so that you can use code in wsl/Ubuntu.

Another gotcha to lookout for is that VSCode insiders is launched with code-insiders not code. If that's your scenario, then use the following to create a softlink named code that will call code-insiders.

ln -s "$(which code-insiders)" ~/.local/bin/code

like image 43
rainabba Avatar answered Oct 16 '25 23:10

rainabba