Winget-cli: winget does not run in WSL2 due to exec format error

Created on 20 May 2020  路  3Comments  路  Source: microsoft/winget-cli

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.

Issue-Feature

Most helpful comment

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

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

denelon picture denelon  路  4Comments

brunovieira97 picture brunovieira97  路  3Comments

sayedarifuddin picture sayedarifuddin  路  3Comments

ermshiperete picture ermshiperete  路  3Comments

Callidior picture Callidior  路  5Comments