Visual Studio Code not running/working on WSL 2 - visual-studio-code

Somehow when I run code . inside the WSL, it simply doesn't do anything. If I which code it does return the VS Code path on windows, but still nothing happens.

Well, after some research, what really fixed the issue for me was the following:
Within the WSL terminal, type rm -r ~/.vscode-server to delete the VS Code WSL server.
Exit the terminal and from your PowerShell/Cmd, run wsl --shutdown.
Then you can log in back to your WSL and run code . and it should work normally.

I solved it following this post with slight modifications.
exit all instaces of wsl
From the power shell run wsl --shutdown
Start VS Code on Windows
Open a previously saved project which uses wsl (this is the difference)
Open wsl and run code . starts VS Code for me
Note: the issue appeared for me after upgrading to wsl2

Related

Visual studio code command doesn't work on WSL 2

For some reason, when I type the command code . from a WSL terminal I have the message:
Command is only available in WSL or inside a Visual Studio Code terminal.
After some research, I tried to fix it with the following commands:
rm -r ~/.vscode-server
code .
It redownloads VS Code Server and it works correctly but just for one terminal instance. When I open a new terminal, I still have the message :
Command is only available in WSL or inside a Visual Studio Code terminal.
I don't have the issue when I use the command code in a VS code terminal.

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 ?

Looking for help on setting up wsl in vscode terminal

If I'm in my terminal and open a file with the code command, vscode will launch and the terminal inside code will show my full zsh setup that I have configured in hyper terminal. But if I open up code through windows, and select wsl as my default shell, it's pretty much useless. Anything I try, like sudo, git, apt, etc will return a command not found message.
So if I want to commit any changes in the terminal inside code then I have to use the git bash shell. Is it possible to get my zsh working without first launching from my terminal emulator so I'm using wsl instead of git bash?
running wslconfig.exe /list in powershell showed me that WSL was set to docker as the default shell, so then running wslconfig.exe /setdefault "Ubuntu" in powershell fixed my problem.

How to open a file from terminal in a tmux session in Visual Studio Code

One can open a file from the integrated terminal in Visual Studio Code via:
code -r something.dat
Unfortunately, this does not work for me when I work in the terminal within a tmux-session. The error I get is:
-bash: code: command not found
I googled the error and it seems I have to include vscode on my Path variable (example: similar problem).
I'm now confused on what to do as it works from the normal integrated terminal but doesn't work in the tmux "environment".
Do you have any ideas?
Probably you first started the tmux server from a terminal without this in PATH and you are not adding it in any of the shell startup files that the shell uses when started from tmux (remember tmux starts login shells by default).

VS Code doesn't add command line on path permanently on Mac

I am using VS code 1.8.1 on Mac 10.12.3 (16D32). After launch vscode, I run cmd shift p to open command search field. Then run Install code command in Path. I can see the code got added on PATH but it got removed after I close vs code. Is there a way to add it permanently?
So I've just had this issue during setup of a new laptop and found a simple (but slightly embarrassing) solution that worked for me. After faffing about with it for way too long I noticed I had left it in Downloads. I moved the .app file to /Applications and ran the command-line install function again and now the "code" command persists.
Add this to your ~/.bash_profile
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
source: https://code.visualstudio.com/docs/setup/mac
I am assuming you've checked this link.
VSCode application generally resides in /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code.
Follow these steps to access VSCode through code on shell.
Open bash_profile page
sudo vi /etc/paths
Add an extra line in the list of PATH folders as
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/
Exit from vi: Esc > :wq! > Enter Key
Restart shell. Then do echo $PATH to confirm VSCode has been added successfully.
Check code command is added by typing which code. You should see VSCode path printed on screen.
Try this link if it doesn't work out.
Edit: I am using version 1.9.1 and after I ran Install code command in Path it got added permanently.
Visual Studio Code
rm /usr/local/bin/code
ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code
Visual Studio Code - Insiders
rm /usr/local/bin/code-insiders
ln -s "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code" /usr/local/bin/code-insiders
For Big Sur:
From the official docs:
Note: Since zsh became the default shell in macOS Catalina, run the
following commands to add VS Code to your path:
cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code) export PATH="\$PATH:/Applications/Visual Studio
Code.app/Contents/Resources/app/bin" EOF
I did this and it worked for me.
I am running Visual Studio Code - Insiders 1.23.0 on a Mac/Mac OS 10.10.5 Yosemite. I added the "Shell Command: Install 'code-insiders' command in PATH" from within VSC - Insiders. From the terminal in any directory I just add 'code-insiders .' and it launches in VSC - Insiders without issue.
Hope that helps.
For me, the problem was that Visual Studio Code.app was not in the Applications folder, but rather in the Downloads folder. Moving it there and re-running the add to path command fixed it for me.