Score:0

I cannot open Visual Studio Code using terminal on WSL Ubuntu

br flag

I am pretty sure, I have VS code on my WSL Ubuntu. But when I run the command code to open VS code it does not seem to work. I have also tried running the following command:

sudo apt install

But I get an error:

E:cannot locate package error

How do I open VS Code?

NotTheDr01ds avatar
vn flag
What's the error you get (if any) when you type `code`? Also, `sudo apt install` isn't a complete command -- *What* package did you try to install? Regardless, VSCode shouldn't be installed into WSL with `apt`, but if you did, it could be masking the Windows version, which is what you really should be using in WSL.
Score:1
tr flag

Once you have WSL installed you need to load the VS Code onto you host Windows system. Once you have VS Code installed you can then install the remote development tools. This will give you the ability to connect to the Linux virtual machine directly from Windows.

Now you get to the point where you will install the VS Code into Linux: open the WSL prompt and change directory to /mnt/c — this will place you into the host disk space c-drive — enter the command code . into the WSL and it should start installing all the necessary libraries automatically. If it doesn't (it didn't for me) then you need to close down and restart the WSL. Once it has fully installed you should see a tag similar to >< WSL in the bottom left corner of the VS Code IDE.

Hope that helps.

Yugoo avatar
br flag
it was running earlier, but I restarted my laptop and all of a sudden it does not work anymore.
Geoff Riley avatar
tr flag
@Yugoo, can you confirm exactly how you have your system set up? If it stopped working after a reboot then there is a step that you made manually originally that you missed out of the permanent set up. '…does not work anymore' isn't a very helpful report to work with, we need to know what you tried, what did happen and what you expected to happen.
Yugoo avatar
br flag
Thank you. I am running WSL ubuntu on windows 10. I followed the instruction on downloading vs code here https://code.visualstudio.com/docs/remote/wsl#_getting-started. I use the command "code ." to open and run vs code from the terminal. I had to restart my laptop and when I run the same command to open vs code I get a command not found error.
Geoff Riley avatar
tr flag
Curious, does VS Code run correctly when started from the 'Start' menu on Windows? If it does it should automatically detect the presence of the WSL. Your setup is as mine is in that respect.
Score:0
in flag

I had the same problem as you and I found there was a problem with the PATH route. Check your $PATH in the Linux terminal with the following:

echo $PATH

Check the outcome and you may get a route that looks like this:

/mnt/c/Users/banana/AppData/Local/Programs/Microsoft:VS:Code/bin

If you check the route it is not the correct route where VS code is installed in windows because the folder is in 'Microsoft VS Code' no 'Microsoft:VS:Code'. You may check this fact by running these two code lines:

cd /mnt/c/Users/banana/AppData/Local/Programs/Microsoft:VS:Code/bin

cd /mnt/c/Users/banana/AppData/Local/Programs/Microsoft\ VS\ Code/bin

The first line should show that the folder doesn't exist and the second one will work.

To solve this add the following line at the end of your .bashrc file:

PATH=$PATH:/mnt/c/Users/banana/AppData/Local/Programs/Microsoft\ VS\ Code/bin

The previous code line appends the new path to your $PATH without modifying the current PATH configuration.

Let me know if this works.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.