返回文章列表文章索引阅读全文
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 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

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

加载评论中…

Fix the issue where the winget command is not found. · StarBlog