When invoking winget from WSL it does not run due to exec format error
I run $HOME/AppData/Local/Microsoft/WindowsApps/winget.exe
Winget shows me a list of command options
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.
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 (or source ~/.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
Most helpful comment
I have figured out a workaround for this.
Open your
~/.bashrcfile in your editor of choice (or~/.zshrcif 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