Fix the issue where the winget command is not found.
Microsoft's official package manager, winget, is used in Windows 10 version 1809 and above for quickly installing, updating, and managing applications. This article addresses the issue where the winget command fails due to changes in the system environment, analyzes possible causes, and provides solutions and preventive measures, including repair commands, regular update checks, and backup of environment variables.
目录9 个章节
Preface
winget is Microsoft's official Windows package manager, which is typically automatically included in Windows 10 version 1809 and later. It allows you to quickly install, update, and manage applications through the command line and is a highly practical tool within the Windows ecosystem.
Problem Description
My computer previously had my environment configured and I had been using winget stably for a long time. However, recently when I execute winget commands, it suddenly started giving errors:
winget: The term 'winget' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Possible Causes
- Windows Update may have unexpectedly modified system environment variables
- The App Installer component may have been accidentally uninstalled or corrupted
- The winget executable file in the system path may have been moved or deleted
- User permission issues prevent access to winget
Although reinstalling can solve the problem, considering the time cost and existing configuration, I decided to seek a more efficient repair solution.
Detailed Repair Steps
Step 1: Try Installing the WinGet Client Module
Based on community recommendations, first attempt to install the Microsoft.WinGet.Client PowerShell module:
Run PowerShell as Administrator
Install-Module -Name Microsoft.WinGet.Client -Force
This module provides additional winget management capabilities, but installing it alone does not resolve our issue.
### Step 2: Execute Repair Command
The truly effective solution is to use the repair command that comes with the Windows package manager:
```powershell
# Run PowerShell as Administrator
```powershell
Repair-WinGetPackageManager
This command will:
- Check and repair the App Installer component
- Re-register winget-related components
- Restore system environment variable settings
After execution, it is recommended to restart your computer to ensure all changes take effect.
Preventive Measures and Maintenance Suggestions
- Regularly Check Updates: Keep Windows and App Installer up to date.
- Back Up Environment Variables: Export the PATH environment variable as a backup.
- Create System Restore Points: Before making major system changes, create a restore point.
- Use winget export: Periodically export the list of installed software.
Further Reading
FAQ
Q: What to do if the fix command still doesn't work? A: You can try manually installing the latest version of App Installer or fully reinstalling winget.
Q: How to verify if winget is working properly?
A: Run winget --version to check the version number, or winget search to test the search functionality.
_EOF_
Fix the issue where the winget command is not found.
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
在 Windows11 上启用 ssh-agent
微软的坑真多!!!
2026-08-25 · Windows · 约 1 分钟
Windows设置Pageant开机自动启动并且加载秘钥
场景 用Linux的时候ssh和git这些很方便,因为只要一次ssh-add就可以一劳永逸,以后需要认证的时候ssh-agent会帮我们搞定,不需要输入秘钥的密码。 其实Windows也可以实现这种生产力解放,就是用putty附带的工具里的Pageant。 Pageant主要负责和服务器端进行身份验证,但是每次在启动Pageant后都需要手动的加载秘钥文件,本文就是要介绍让Pageant开机自动加
2021-12-18 · Windows · 约 1 分钟
使用twinkle-tray快捷调整多个显示器的亮度
自从安装了这个小工具,我再也没用过笔记本键盘上的快捷键了~
2025-01-26 · Windows · 约 1 分钟
如何阻止Win10重置默认应用?
前言 Win10比之前版本的Windows系统更现代,然而却不见得更好用,喜欢自作主张重置默认应用就是一个大问题。 就像这样,真的是烦。 解决方法 改注册表。 新建一个 去除重置默认应用.reg 的注册表文件,粘贴一下代码。 Windows Registry Editor Version 5.00 ;Description: Prevents Windows 10 from resetting
2021-12-18 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…