Skip to main content

Fixing VS Code/Code.exe: Exec format error in WSL

ยท 2 min read
Adrian Escutia
A Rebel with a Cause, Innovating the Future

From time to time, we run into issues that seem trivial but can be quite frustrating, when VS Code doesn't open from WSL, it can be one of those issues and it happens after a Windows update or a VS Code update. Here's how to fix it.

I recently ran into an issue where I couldn't open Visual Studio Code from WSL. I would get the following error:

$ code .
/c/Users/adria/AppData/Local/Programs/Microsoft VS Code/bin/code: 61: /c/Users/adria/AppData/Local/Programs/Microsoft VS Code/Code.exe: Exec format error

Read on to learn how to fix this issue.

This error is due to the fact that the Windows executable is not compatible with the Linux environment. The solution is to create a symbolic link to the Windows executable from the Linux environment. The solution is simple, but it can be frustrating if you don't know what to do, eventually, you might end up reinstalling VS Code or even WSL; don't do that, I got you covered.

Here's how to fix it:

$  sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf'
[sudo] password for $USER:
$ sudo systemctl unmask systemd-binfmt.service
$ sudo systemctl restart systemd-binfmt
$ sudo systemctl mask systemd-binfmt.service
Created symlink /etc/systemd/system/systemd-binfmt.service โ†’ /dev/null.
$ code .

That's it! You should now be able to open Visual Studio Code from WSL without any issues. If you still have issues, try restarting your WSL session.

I hope this helps you fix the issue. If you have any questions or comments, feel free to reach out, send me a message here or on LinkedIn. I'm always happy to help. ๐Ÿ˜Š

Referencesโ€‹


By continuing you agree to our

Privacy Policy