[FIXED] How to install Visual Studio Code on WSL2?

Issue

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.

Solution

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!

Answered By – quoc9x

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published