Visual Studio Code Terminal bash vs. Ubuntu for Windows 10 bash - visual-studio-code

I just started with VS Code today as I have to prepare to port some of my code to Linux and I noticed that in the Terminal section there is the option of having a WSL bash, so I thought I could use this to compile my projects with gcc right there. I already installed Ubuntu for Windows 10 from the MSFT Store some time ago an installed several packages there. The thing is that the Ubuntu bash doesn't seem to share to the Linux workspace with the bash I see in VS Code, since in the latter I am lacking all those packages I already installed; it seems to be a completely different installation. Also, I noticed that the bash in the VS Code terminal uses German language while the Ubuntu App's bash is in English. (I have no idea why this is since Windows as well as VS Code is English.)
I'm quite confused about these differences, how do ubuntu.exe and bash.exe relate to each other? Can anybody shed some light on this? Obviously, it would be preferrable to to have only ONE Linux workspace in WSL so I don't have to have duplicates (of my data and also the installed packages) at different places.

To use WSL bash in VS Code integrated terminal, you need to add/change setting:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe",
Restart VS Code or integrated terminal.
If two or more WSL distro are installed, then you need to specify the path to the desired distro.
For example you can find it by running: where ubuntu, where ubuntu1604 or where ubuntu1804. And change the settings to the desired ones. For example:
"terminal.integrated.shell.windows": "C:\\Users\\USERNAME\\AppData\\Local\\Microsoft\\WindowsApps\\ubuntu1604.exe",

Related

vscode inside WSL vs Windows

In tutorial requirement is install vscode in windows and install Remote Development extension pack. Why not just install in wsl?
I've install vscode to wsl. When I run code in wsl I get 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.
Do you want to continue anyway? [y/N]
To no longer see this prompt, start Visual Studio Code with the environment variable DONT_PROMPT_WSL_INSTALL defined.
Which cons of run vscode in wsl as opposed to run it in Windows?
The WSL extension splits VS Code into a “client-server” architecture, with the client (the user interface) running on your Windows machine and the server (your code, Git, plugins, etc) running "remotely" in your WSL distribution.
When VS Code is started in WSL, no shell startup scripts are run.
The extension runs commands and other extensions directly in WSL so you can edit files located in WSL or the mounted Windows filesystem (for example /mnt/c) without worrying about pathing issues, binary compatibility, or other cross-OS challenges.
(source: MSFT DOCUMENTATION)
This is the architectural choice of Windows and - personally speaking - I feel like it's a choice to avoid conflicts and redundancies.
When running the WSL extension, selecting the 'Extensions' tab will display a list of extensions split between your local machine and your WSL distribution.
Installing a local extension, like a theme, only needs to be installed once.
Some extensions, like the Python extension or anything that handles things like linting or debugging, must be installed separately on each WSL distribution. VS Code will display a warning icon ⚠, along with a green "Install in WSL" button, if you have an extension locally installed that is not installed on your WSL distribution.

why my vscode does not have the same libraries installed in wsl?

I'm using wsl and it runs codes in vscode pretty fine and I have different libraries which I installed through pip and conda in wsl but when I run that code using vscode itself it doesn't recognize the libraries or even pip itself.
I don't have any other environment.
I should add that I installed the packages globally using conda install ... or pip install ... in base environment and I only have base environment and I run my code through code . and I also have python and remote wsl extensions installed in my vscode.
what can be the problem?
I don't have much personal experience with this, but I found some useful information in this Stack Overflow question (even though it doesn't utilize conda), along with https://code.visualstudio.com/docs/remote/wsl-tutorial#_python-development.
I also found this blog post useful, even if it doesn't cover WSL.
In short, make sure you:
Have installed the Python extension (by Microsoft) in VSCode. This is critical for being able to detect and select the Python interpreter. You don't mention having this in place, so I believe this is your likely problem.
You have done this already, but including it for others who might read this later -- Install the Remote - WSL extension (or the Remote Development extension pack) in VSCode.
You are also doing this already -- Start VSCode from inside your WSL distribution. Alternatively, you can start VSCode from Windows and then select the Remote WSL - Reopen Folder in WSL from the Command Palette (also accessible from the "Remote" Status Bar).
In VSCode, open the Command Palette with Shift+Ctrl+P, search for the Python: Select Interpreter command, and you should find your Conda environment in the list.
After selecting this, you should find that your project is using the interpreter and modules that you have installed via conda.
One thing I did to overcome this issue is go to Extensions -> Local (You should have two tabs there, Local and WSL:DISTRO) DISTRO refers to whatever DISTRO you're using, you will see that some of the local extensions are disabled in the current workspace (WSL) and there is a little cloud icon in the WSL:DISTRO tab that says install Local Extensions in WSL:DISTRO once you click that it will let you choose which extensions to install and you should be good to go!

Strange vscode issue in WSL

I've been trying to set up the vscode code . shortcut to work in WSL. Following the instructions from the vscode website, I reinstalled vscode in windows, reinstalled the Remote-Wsl extension, made sure it was in my System Path, and tried running code . in the WSL linux distro terminal. I get the message instructing me to install it on the windows side, and asking me if I want to continue. I hit yes, but it doesn't create the code server folder in my home directory. Typing code . again does the same thing.
Does anyone know why this may be?
This is the output text:
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.
Do you want to continue anyway? [y/N]
The error message isn't just pointing out that you need to install the Windows version, but it indicates that you have the Linux version installed in WSL and should remove it.
From that, it sounds like at some point you may have installed the Linux version of VSCode in WSL, and that one is taking priority. You'll need to uninstall it in order to run the Windows version of VSCode with the "Remote - WSL" extension.
You don't mention what distribution you are running, but if it is Ubuntu, try:
sudo apt remove code # or
sudo apt remove code-insiders
Also see the uninstall doc from Microsoft.

nvm and gulp found on Visual Code terminal but not on linux terminal

I have Ubuntu LTS 20.04 running on wsl2 in Windows, this way I'm able to compile my JS/React code and run my php server in linux and use windows to code using Visual Studio Code.
This is running great, but a strange thing is happening, I installed nvm and gulp through the Visual Studio Code terminal and if I use them on the terminal it works fine but not if I do it outside the terminal (using Windows terminal), it says not found for both gulp and nvm.
I assume VSCode is adding a few things to the PATH but I don't know what to do for them to be found by the windows terminal (outisde VSCode terminal). Screen below. On the left is the result of running nvm list inside VS Code terminal and on the right on Ubuntu terminal, which can't find.
I'm a bit confused by your question. It sounds like you're installing programs on Windows through the VSCode terminal, and then trying to run them on Windows but it's not working. But then your screenshot shows the WSL Ubuntu prompt failing to find the command. Assuming you want to run these under WSL, log in to WSL Ubuntu and run this:
find / -name nvm
If you actually want to use the Windows terminal to run the program, you'll have to find where it is installed in Windows and make sure that's in your %PATH% but this doesn't seem like it's what you're trying to do.
The correct answer was provided by the comment from MindSwipe.
On VSCODE terminal if I "echo $PATH" it has the nvm directory in it while the $PATH on WSL doesn't, I assume VSCODE alters its own terminal PATH when the tools are installed using it instead of the global WSL path.
I've changed the WSL path and it's now working, how can I present the bounty to MindSwipe ?

How to Access Linux Files in a WSL distro from Windows 10?

Recently I updated my Windows 10 Pro with May Update (version 1903, build 18362.116). Then for my existing distros: OpenSuse Leap 15 and Ubuntu (installed from MS Store), I wanted to open a linux directory by using Explorer and I'm getting this message:
[susedis#mypc ~]$ explorer.exe .
If 'explorer.exe' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf explorer.exe
This problem happens also with VSC (code) and VSC-Insiders (code-insiders).
I've read this article and ...
OPTION 1: my current problem
OPTION 2: icon LINUX does not exist in tree view
OPTION 3: it works
Supposedly options 1 and 2 should exist and work, even more with the latest update. What's wrong? Thanks in advance.
PS1: I've found these articles Run Visual Studio Code for Linux from WSL and Using Visual Studio Code with Windows Subsystem for Linux, they talk about installing xserver and more stuff on side linux. But many other articles and videos don't talk about it, it's like it was a built-in feature of Windows. This is so dark.
I just found what is the root of my problem: the distro.
explorer, code, code-insiders commands ONLY work through UBUNTU and I was using OpenSuse.
This warning is lacking in every article on Web I read, including on VSC site (example: Developing in WSL). This is a disadvantage for other distros. Very bad.
PS1: The solution can be found here.