How to Use the Command 'winget' (with examples)
- Windows
- December 17, 2024
Winget, or the Windows Package Manager, is a command-line tool created by Microsoft to simplify the process of discovering, installing, upgrading, removing, and configuring applications on Windows 10 and Windows 11. It streamlines package management by allowing users to use a simple command interface to handle various package operations, much like package managers on Linux and macOS. This helps in maintaining software and keeping it updated with minimal hassle, bridging the gap between development environments on different operating systems.
Install a Package
Code:
winget install package
Motivation:
Installing a package is one of the most common uses of a package manager. When you need a new application for productivity, software development, or entertainment, the winget install package
command simplifies the process. Instead of searching for an executable installer, downloading it, and manually running through an installation wizard, a single command handles it all effortlessly.
Explanation:
winget
: The core command to interact with the Windows Package Manager.install
: The action or operation to perform with winget.package
: Placeholder for the actual package name, such as ’notepad++’, which you intend to install.
Example Output:
Found Notepad++ [Notepad++.Notepad++]
This application is licensed to you by its owner.
Downloading and installing...
Successfully installed!
Remove a Package
Code:
winget uninstall package
Motivation:
Over time, your system might accumulate applications that are no longer needed, taking up valuable hard drive space. Being able to remove these applications swiftly through winget uninstall package
ensures that you maintain cleaner and more efficient system performance without having to navigate the Control Panel.
Explanation:
winget
: Access the package manager.uninstall
: Initiates the removal process for a specified package.package
: The specific software package you wish to remove, like ‘vscode’.
Example Output:
Uninstalling Visual Studio Code [Microsoft.VisualStudioCode]
Successfully uninstalled!
Display Information About a Package
Code:
winget show package
Motivation:
Before installing or updating a package, you might wish to know more about it. Information such as version numbers, publisher details, and description can be obtained using winget show package
. This is useful for verifying details about the software before making changes to your system.
Explanation:
winget
: The package manager command.show
: Fetches details of the given package.package
: Name of the application, for example, ‘7zip’.
Example Output:
Id: 7zip.7zip
Version: 19.00
Publisher: Igor Pavlov
Description: 7-Zip is a file archiver with a high compression ratio.
Search for a Package
Code:
winget search package
Motivation:
When unsure of a package’s exact name or when exploring new applications to solve a particular problem, winget search package
provides a way to find available software in the repository. This broadens your ability to discover new tools and verify their existence.
Explanation:
winget
: Engages the winget utility.search
: Keyword for looking up packages.package
: Term to search within available packages like ‘python’.
Example Output:
Name Id Version Source
-----------------------------------------------------------
Python Python.Python 3.9.7 winget
Upgrade All Packages to the Latest Versions
Code:
winget upgrade --all
Motivation:
Regularly updating applications ensures security patches and new features are applied. Rather than updating each application individually, using winget upgrade --all
can automate this process, saving time and ensuring all software remains up-to-date.
Explanation:
winget
: Windows Package Manager utility.upgrade
: Command to update software.--all
: Flag that specifies to apply updates to all managed packages.
Example Output:
Starting upgrade...
Upgrading PowerToys PowerToys.PowerToys 0.29.3 -> 0.31.2
Upgrading Notepad++ Notepad++.Notepad++ 7.8.8 -> 8.1.9.2
Successfully upgraded packages.
List All Packages Installed That Can Be Managed with winget
Code:
winget list --source winget
Motivation:
Keeping track of all the applications installed on your system is crucial for management and auditing. By listing all available packages, you can see which applications can be managed by winget and decide on future actions, be that upgrades or removals.
Explanation:
winget
: The Windows Package Manager.list
: Command to display available packages.--source winget
: Filter to show packages managed by winget specifically.
Example Output:
Name Id Version
------------------------------------------------------
Visual Studio Microsoft.VisualStudio.C++ 2022 17.0.5
Notepad++ Notepad++.Notepad++ 8.1.4
Import Packages from a File, or Export Installed Packages to a File
Code:
winget import --import-file path/to/file
or
winget export --output path/to/file
Motivation:
When setting up a new system or backing up configuration, it helps to export a list of currently installed packages. Similarly, importing from a file can facilitate replication of environments across different machines, ensuring consistency and saving time in configuration efforts.
Explanation:
winget
: Calls the package manager tool.import|export
: Operations for package management from and to files.--import-file|--output
: Path specification for input or output.path/to/file
: The actual file path where the package information is stored or retrieved.
Example Output (for export):
Exporting list to packages.json...
Successfully exported: packages.json
Validate Manifests Before Submitting a PR to the winget-pkgs Repository
Code:
winget validate path/to/manifest
Motivation:
Contributing to the winget-pkgs repository requires precision in submitting manifests. Validating manifests ensures they meet the necessary schema and requirements, reducing errors and facilitating smoother contributions to the community-run software source.
Explanation:
winget
: Invokes the package manager.validate
: Perform checks on the specified manifest.path/to/manifest
: Path leading to the manifest file prepared for submission or validation.
Example Output:
Validating manifest...
No errors found!
Conclusion:
Winget provides a powerful and efficient means of managing software on Windows, drawing parallels with package managers from other operating systems. By mastering these use cases, users can streamline their software management approach, save time on routine tasks, and maintain a clean, updated, and well-documented software environment.