如何使用Windows 10内置程序包管理器?


13

我发现Windows 10软件包管理不是​​很直观。以下是我尝试安装VLC的经历,这听起来像是软件包管理器中非常常见的测试用例。

Find-Package vlc

Find-Package -Update

Install-Package --help

Install-Package /?

Install-Package vlc

The provider 'nuget v2.8.5.127' is not installed.
nuget may be manually downloaded from https://oneget.org/nuget-anycpu-2.8.5.127.exe and installed.
Would you like PackageManagement to automatically download and install 'nuget' now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):
Install-Package : No match was found for the specified search criteria and package name 'vlc'.
At line:1 char:1
+ Install-Package vlc
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Register-PackageSource -Name chocolatey -Location http://chocolatey.org/api/v2 -Provider PSModule -Trusted -Verbose

也许?

Install-Package vlc
WARNING: The module 'vlc' cannot be installed or updated because it is not a properly-formed module.



Install-Package -Name VLC Install-Package : No match was found for the specified search criteria and package name 'VLC'.
乔纳森

有没有Find-Package -Name VLC找到适合您的东西?另外,请检查是否区分大小写。
MC10 2015年

Find-Package -Name VLC查找包:找不到与指定搜索条件和包名称“ VLC”匹配的内容。在第1行:1字符:1 +查找包-名称VLC + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(Microsoft.Power ... ets .FindPackage:FindPackage)[Find-Package],例外+ FullyQualifiedErrorId:NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
Jonathan

1
您可能想先做update-help
BrunoLM

Answers:


10

你近了 首先,您必须将执行策略设置为允许脚本,否则它将在报告成功(错误)时无提示地失败:

Set-ExecutionPolicy RemoteSigned

程序包提供程序(巧克力插件)和程序包源(特定Chocolatey存储库的URL)都需要在PackageManagement中安装/注册。带有-Force标志的Get-PackageProvider 导致其引导,这显然可以同时解决这两个问题(有关的更多帮助-Force):

Get-PackageProvider Chocolatey -Force | Out-Null

然后,我可以搜索该包:

Find-Package vlc -Force

Name       Version          Source           Summary
----       -------          ------           -------
vlc        2.2.1.20150630   chocolatey       VLC Media Player

并安装它(-Force因此它不会提示您进行确认):

Install-Package vlc -Force | Out-Null

在此处输入图片说明


在干净的Windows 10 RTM上,这对我不起作用,它只是将所有内容放入C:\ Chocolatey \ lib,但实际上并未安装程序或运行所需的脚本。
RedShift 2015年

3
哦,PackageManagement中有一个令人困惑的错误,在该错误中会发生确切的行为,除非在安装软件包之前,将执行策略设置为允许脚本(我使用RemoteSigned)。我将更新我的答案。
Vimes

1
很高兴听到。希望他们能消除这些皱纹。如果您喜欢的话,请不要忘记标记答案:-)
Vimes

如何在一行中安装多个软件包?这是所有程序包管理器的行业标准。如果我跑步,似乎会出现错误Install-Package vlc firefox -Force
Jonathan

1
@JonathanLeaders,只需在软件包名称之间添加逗号。
Vimes
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.