winget-cli
winget-cli copied to clipboard
winget does not run in WSL2 due to exec format error
Brief description of your issue
When invoking winget from WSL it does not run due to exec format error
Steps to reproduce
I run $HOME/AppData/Local/Microsoft/WindowsApps/winget.exe
Expected behavior
Winget shows me a list of command options
Actual behavior
Failed to execute process '/mnt/c/Users/mdale/AppData/Local/Microsoft/WindowsApps/winget.exe'. Reason:
exec: Exec format error
The file '/mnt/c/Users/mdale/AppData/Local/Microsoft/WindowsApps/winget.exe' is marked as an executable but could not be run by the operating system.
Environment
WSL2 with Ubuntu, running on slow ring insider build 19041. Winget does run from PowerShell. The path I used is from Get-Command winget in Powershell.
Just to be clear, I don't expect winget to install things inside WSL, but WSL is my default shell, and I run other windows commands from inside there. I'd still like to be able to provision windows apps like Visual Studio from my WSL shell.
But I agree this isn't to replace snap/apt etc.
I have same expectations about winget as @mdales. It should work well with wsl2 and windows terminal as a complete development and package manager environment (that was missing in windows as many devs/pro users were forced to move to Ubuntu).
I have figured out a workaround for this.
-
Open your
~/.bashrc
file in your editor of choice (or~/.zshrc
if you use zsh instead of bash) -
Add the following line at the end of the file
function winget { cmd.exe /c "winget $1 $2 $3";}
-
Then launch
source ~/.bashrc
(orsource ~/.zshrc
) if you don't want to relaunch your shell.
And winget should work inside a WSL2 shell.
I hope this is helpful.
EDIT: Figured out you would need 3 variables for passing additional commands/options
EDIT: Figured out you would need 3 variables for passing additional commands/options
Thanks @jusefn this is just what I was looking for. I did notice that I was getting a UNC error when I used your function so I added the cd command to fix that error. I also added the $@ parameter which will just pass as many parameters that you pass, may that be 1, 2, 3, ...
function winget { (cd /mnt/c; cmd.exe /c "winget $@";) }
In my case (Windows 10 21H2, build 19044.2130) the behaviour is even worse. No error message is being shown, no error status code returned. The system behaves as if the command executed correctly:
~$ winget.exe
~$ echo $?
0
~$ /mnt/c/Users/vaclav.brozik/AppData/Local/Microsoft/WindowsApps/winget.exe
~$ echo $?
0