English

Windows下使用 winget 工具安装和管理应用程序

6/13/2024
35

Winget 是windows 下的应用管理工具,仅在 Windows 10 1709(版本 16299)或更高版本上受支持。

下面以安装 DockDB 为例,介绍 winget 工具。

安装和替换镜像源

一般都预装了, 可以使用命令检查一下:

Bash
$ winget --help
Windows Package Manager v1.7.11261
Copyright (c) Microsoft Corporation. All rights reserved.

The winget command line utility enables installing applications and other packages from the command line.

usage: winget  [<command>] [<options>]

The following commands are available:
  install    Installs the given package
  show       Shows information about a package
  source     Manage sources of packages
  search     Find and show basic info of packages
  list       Display installed packages
  upgrade    Shows and performs available upgrades
  uninstall  Uninstalls the given package
  hash       Helper to hash installer files
  validate   Validates a manifest file
  settings   Open settings or set administrator settings
  features   Shows the status of experimental features
  export     Exports a list of the installed packages
  import     Installs all the packages in a file
  pin        Manage package pins
  configure  Configures the system into a desired state
  download   Downloads the installer from a given package
  repair     Repairs the selected package

For more details on a specific command, pass it the help argument. [-?]

The following options are available:
  -v,--version              Display the version of the tool
  --info                    Display general info of the tool
  -?,--help                 Shows help about the selected command
  --wait                    Prompts the user to press any key before exiting
  --logs,--open-logs        Open the default logs location
  --verbose,--verbose-logs  Enables verbose logging for winget
  --disable-interactivity   Disable interactive prompts

More help can be found at: https://aka.ms/winget-command-help

如果 winget 命令找不到,则去应用商店安装:https://apps.microsoft.com/detail/9nblggh4nns1?activetab=pivot%3Aoverviewtab&hl=en-us&gl=US#activetab=pivot:overviewtab

如果是国内用户建议 更改软件镜像源

Bash
winget source remove winget
winget source add winget https://mirrors.ustc.edu.cn/winget-source

检索软件

Bash
$ winget search duckdb
Name       Id         Version Source
-------------------------------------
DuckDB CLI DuckDB.cli 1.0.0   winget

可以看到有 DuckDB 存在可以被安装

安装

Bash
// 基于名称或者id安装
winget install 'DuckDB CLI'

// 基于名称或者id安装
winget install DuckDB.cli

// 限制基于名称安装
inget install --name 'DuckDB CLI'

// 限制基于id安装
winget install --id DuckDB.cli

显示安装列表

Bash
$ winget list | grep 'DuckDB'
DuckDB CLI                               DuckDB.cli                                1.0.0                         winget
(base)

显示包信息

Bash
$ winget show DuckDB.cli
Found DuckDB CLI [DuckDB.cli]
Version: 1.0.0
Publisher: DuckDB
Publisher Url: https://www.duckdb.org/
Publisher Support Url: https://github.com/duckdb/duckdb/issues
Author: Stichting DuckDB Foundation
Moniker: duckdb-cli
Description:
  DuckDB is a high-performance analytical database system.
  It is designed to be fast, reliable and easy to use.
  DuckDB provides a rich SQL dialect, with support far beyond basic SQL.
Homepage: https://github.com/duckdb/duckdb

卸载

Bash
$ winget uninstall DuckDB.cli

参考: