我发现 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.
没有
答案1
你已经接近成功了。首先,你必须设置执行策略以允许脚本,否则它会在报告成功时默默失败(漏洞):
Set-ExecutionPolicy RemoteSigned
软件包提供商(Chocolatey 插件)和软件包源(特定 Chocolatey 存储库的 URL)都需要通过 PackageManagement 安装/注册。带有标志的 Get-PackageProvider-Force
会使其启动,这显然会同时处理这两者(有关帮助的更多信息-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