Once you installed WSL2 you might face with different issues, for example your hot reload server is not working anymore comparing to WSL 1, or your build/compilation become ultra slow.
Why? Because all hot-reload servers are inotify-api based, and you probably still serve project from your windows FS like you did in WSL1. And what? And WSL 2 is a virtual machine with separate virtual hard drive, which is actually now a one file in your windows FS 😲:
WSL 1 had rootfs with nested folders tree here, in the same folder, but not WSL 2.
So what is windows FS and what is Linux FS now then?
- From WSL 2 perspective everything that outside of
/mntis linux fs. For example
- Mounts like
/mnt/c/are Windows FS and they are outside of
But why you still can access both in terminall? Because WSL interpretator cares about it. In reality you can't even navigate to linux FS via Windows Explorer (at least in early releases).
How to fix hot-reload and inotify is not working in WSL2?
So it is not working because inotify hooks installed by your Node or Python process can't track updates from Windows filesystem. Also access to Windows file system is now slower because it works through virtual machine mounts.
To fix it just recreate or copy your project to WSL filesystem:
cp -R /mnt/c/pro/project_folder ~/project_folder
But how to work then if you can't access filesystem🤔?
Answer is VS Code + https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl (WSL Remote Extension)
CTRL + SHIFT + P and type
WSL, then select
Reopen Folder in WSL:
Then select your distro, e.g. mine is 18.04 and you are there! (Better to use 20.04 because it has newer package version in repositories by default)
Good news that you can just use
Reval in explorer feature and WSL will open special network drive so you could e.g. copy assets or even open files in another editor if you need it:
How to fix /bin/sh^M: bad interpreter: No such file or directory
If you run some binary which sits both in WSL 2 PATH and in Windows native PATH, you might face
bad interpreter issue. For example when I installed nodejs and npm into updated WSL 2, I got:
$ npm bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory
This happens because Windows PATH had precedence over WSL PATH. Even despite of fact
npm located correctly:
$ which npm /usr/bin/npm
If you want to check by yourself, run:
And make sure that
/mnt/c/Program Files/ goes before
/usr/local/bin in output.
So to fix it I suggest you disable Windows PATH in WSL environment at all, once and forever:
sudo nano /etc/wsl.conf
And add line:
Now save file and restart terminal, or just re-run
bash to apply change without restarting
How to change default distro in VSCode
Default distro terminology works in your system not in WSL, so just open CMD and check list of your distros:
wslconfig /setdefault Ubuntu-20.04
Recheck list of distros now:
Terminal for WSL 2
You can use terminal from VS Code, but if you don't need it, we recommend to checkout Windows Terminal