曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
Windows

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.

曦远 (DealiAxy)约 8 分钟
目录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

  1. Windows Update may have unexpectedly modified system environment variables
  2. The App Installer component may have been accidentally uninstalled or corrupted
  3. The winget executable file in the system path may have been moved or deleted
  4. 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:

  1. Check and repair the App Installer component
  2. Re-register winget-related components
  3. 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

  1. Regularly Check Updates: Keep Windows and App Installer up to date.
  2. Back Up Environment Variables: Export the PATH environment variable as a backup.
  3. Create System Restore Points: Before making major system changes, create a restore point.
  4. 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 许可协议。转载请注明出处!

相关文章

Kali-Linux-on-WSL2安装与简单配置指南

Windows在更新到2004版本之后正式开启了WSL2的支持,这次是完整的运行在HyperV虚拟机中的Linux系统了,可以称之为真正的Linux了,难不成Windows即将成为最好的Linux发行版? 实际体验下来还是可以的,不过小问题不少,爱折腾的同学安排一手,对提高Windows平台下的开发体验还是有很大帮助的~ Kali on WSL2安装指南 升级系统 首先检查当前系统版本,按Win+

2021-12-18 · Windows · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…