使用 winget 工具來安裝和管理應用程式Use the winget tool to install and manage applications

重要

Windows 封裝管理員和 winget 工具目前處於公開預覽狀態,在正式推出之前,可能會大幅修改。Windows Package Manager and the winget tool are in public preview and may be substantially modified before they are generally available. Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。Microsoft makes no warranties, express or implied, with respect to the information provided here.

winget 命令列工具可讓開發人員在 Windows 10 電腦上探索、安裝、升級、移除和設定應用程式。The winget command line tool enables developers to discover, install, upgrade, remove and configure applications on Windows 10 computers. 此工具是 Windows 封裝管理員服務的用戶端介面。This tool is the client interface to the Windows Package Manager service.

winget 工具目前為預覽版,因此並非所有規劃的功能都可供使用。The winget tool is currently a preview, so not all planned functionality is available at this time.

安裝 wingetInstall winget

安裝 winget 工具的方法有好幾種:There are several ways to install the winget tool:

注意

winget 工具需要 Windows 10 1709 版 (10.0.16299) 或更新版本的 Windows 10。The winget tool requires Windows 10, version 1709 (10.0.16299), or a later version of Windows 10.

系統管理員考量Administrator considerations

安裝程式行為可能會根據您是否以系統管理員權限執行 winget,而有所不同。Installer behavior can be different depending on whether you are running winget with administrator privileges.

  • 如果在沒有系統管理員權限的情況下執行 winget,則可能需要提供某些應用程式的權限才能安裝。When running winget without administrator privileges, some applications may require elevation to install. 當安裝程式執行時,Windows 會提示您提高權限When the installer runs, Windows will prompt you to elevate. 如果您選擇不提高權限,應用程式將無法安裝。If you choose not to elevate, the application will fail to install.

  • 在系統管理員命令提示字元中執行 winget 時,您將不會看到應用程式需要的提高權限提示When running winget in an Administrator Command Prompt, you will not see elevation prompts if the application requires it. 以系統管理員身分執行命令提示字元時,請務必小心,並且只安裝您信任的應用程式。Always use caution when running your command prompt as an administrator, and only install applications you trust.

使用 wingetUse winget

安裝應用程式安裝程式之後,您可以在命令提示字元中輸入 'winget' 來執行 wingetAfter App Installer is installed, you can run winget by typing 'winget' from a Command Prompt.

其中一個最常見的使用案例是搜尋並安裝最愛的工具。One of the most common usage scenarios is to search for and install a favorite tool.

  1. 若要搜尋工具,請輸入 winget search \<appname>To search for a tool, type winget search \<appname>.

  2. 確認您想要的工具可供使用之後,您就可以輸入 winget install \<appname>安裝工具。After you have confirmed that the tool you want is available, you can install the tool by typing winget install \<appname>. winget 工具會啟動安裝程式,並將應用程式安裝在您的電腦上。The winget tool will launch the installer and install the application on your PC. winget 命令列winget commandline

  3. 除了安裝和搜尋之外,winget 還提供一些其他命令,可讓您顯示應用程式的詳細資料變更來源驗證封裝In addition to install and search, winget provides a number of other commands that enable you to show details on applications, change sources, and validate packages. 如需完整的命令清單,請輸入:winget --helpTo get a complete list of commands, type: winget --help. winget 說明winget help

命令Commands

目前的 winget 工具預覽版支援下列命令。The current preview of the winget tool supports the following commands.

命令Command 描述Description
hashhash 產生安裝程式的 SHA256 雜湊。Generates the SHA256 hash for the installer.
說明help 顯示 winget 工具命令的說明。Displays help for the winget tool commands.
installinstall 安裝指定的應用程式。Installs the specified application.
searchsearch 搜尋應用程式。Searches for an application.
showshow 顯示指定應用程式的詳細資料。Displays details for the specified application.
sourcesource 新增、移除及更新 winget 工具所存取的 Windows 封裝管理員存放庫。Adds, removes, and updates the Windows Package Manager repositories accessed by the winget tool.
validatevalidate 驗證資訊清單檔案以提交至 Windows 封裝管理員存放庫。Validates a manifest file for submission to the Windows Package Manager repository.

選項Options

目前的 winget 工具預覽版支援下列選項。The current preview of the winget tool supports the following options.

選項Option 描述Description
-v,--version-v,--version 此選項會傳回目前的 winget 版本。this option returns the current version of winget.
--info--info info 會提供您有關 winget 的所有詳細資訊,包括授權和隱私權聲明的連結。info provides you with all detailed information on winget including the links to the license and privacy statement.
-?, --help-?, --help 取得 winget 的其他說明get additional help winget

支援的安裝程式格式Supported installer formats

目前的 winget 工具預覽版支援下列類型的安裝程式。The current preview of the winget tool supports the following types of installers.

  • EXEEXE
  • MSIXMSIX
  • MSIMSI

以指令碼撰寫 wingetScripting winget

您可以撰寫批次指令碼和 powershell 指令碼來安裝多個應用程式。You can author batch scripts and powershell scripts to install multiple applications.

@echo off  
Echo Install Powertoys and Terminal  
REM Powertoys  
winget install Microsoft.Powertoys  
if %ERRORLEVEL% EQU 0 Echo Powertoys installed successfully.  
REM Terminal  
winget install Microsoft.WindowsTerminal  
if %ERRORLEVEL% EQU 0 Echo Terminal installed successfully.   %ERRORLEVEL%

注意

撰寫指令碼後,winget 會依照指定的順序啟動應用程式。When scripted, winget will launch the applications in the specified order. 當安裝程式傳回成功或失敗時,winget 將會啟動下一個安裝程式。When an installer returns success or failure, winget will launch the next installer. 如果安裝程式啟動另一個程序,其可能會提前傳回 wingetIf an installer launches another process, it is possible that it will return to winget prematurely. 這會導致 winget 在先前的安裝程式完成之前,就安裝下一個安裝程式。This will cause winget to install the next installer before the previous installer has completed.

缺少工具Missing tools

如果社群存放庫未包含您的工具或應用程式。If the community repository does not include your tool or application. 請將封裝提交至我們的存放庫Please submit a package to our repository. 新增您最愛的工具,以便您和其他人使用。By adding your favorite tool, it will be available to you and everyone else.

開放原始碼詳細資訊Open source details

winget 工具是 GitHub 存放庫 https://github.com/microsoft/winget-cli/ 中提供的開放原始碼軟體。The winget tool is open source software available on GitHub in the repo https://github.com/microsoft/winget-cli/. 用於建立用戶端的原始碼位於 src 資料夾The source for building the client is located in the src folder.

winget 的原始碼包含在 Visual Studio 2019 C++ 解決方案中。The source for winget is contained in a Visual Studio 2019 C++ solution. 若要正確建立解決方案,請安裝搭配 C++ 工作負載的 Visual StudioTo build the solution correctly, install the latest Visual Studio with the C++ workload.

我們歡迎您參與撰寫 GitHub 上的 winget 原始碼。We encourage you to contribute to the winget source on GitHub. 您必須先同意並簽署 Microsoft CLA。You must first agree to and sign the Microsoft CLA.