windows 如何设置 Chocolatey 将应用程序安装到另一个驱动器上?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19752533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:02:50  来源:igfitidea点击:

How do I set Chocolatey to install applications onto another drive?

windowschocolatey

提问by Hazz22

I've installed Chocolatey, but I would like it to install programs to another drive instead of C. C is only a small SSD, but I have other drives where I usually install programs to.

我已经安装了 Chocolatey,但我希望它将程序安装到另一个驱动器而不是 C。C 只是一个小型 SSD,但我还有其他驱动器,我通常会在其中安装程序。

Any ideas?

有任何想法吗?

采纳答案by ferventcoder

Chocolatey FOSS

巧克力味

For each application, you would need to know its command line switch used during installation to change its installation directory and pass it using --installArgs. See Install Command (choco install)and Overriding default install directory or other advanced install concepts.

对于每个应用程序,您需要知道它在安装过程中使用的命令行开关来更改其安装目录并使用--installArgs. 请参阅安装命令 (choco install)覆盖默认安装目录或其他高级安装概念

Another way to ensure a different drive is to relocate your Program Filesto a different drive. You may want to look that up; it is possible to do.

确保使用不同驱动器的另一种方法是将您Program Files的驱动器重新定位到不同的驱动器。你可能想查一下;这是可能的。

Chocolatey Licensed Versions

巧克力许可版本

We've added the ubiquitous install switch! If you need to override the install directory and you don't want to do all of the work to determine what that switch is, you have the option to use one switch with Chocolatey - Ubiquitous Install Directory Option (Licensed Editions Only).

我们添加了无处不在的安装开关!如果您需要覆盖安装目录并且不想做所有工作来确定该开关是什么,您可以选择使用一个带有 Chocolatey - Ubiquitous Install Directory Option (Licensed Editions Only) 的开关。

NOTE:We need to ensure the longevity of the Chocolatey community somehow, and that is to have a FOSSium (freemium) model. The Pro version is $8/month (annually $96), costs you less than eating out once a month, gets you some awesome features, and ensures that the community infrastructure continues to provide a great service and improve. While you are using a free service (the community repository, aka https://chocolatey.org/packages), it is not free to provide that service. So we select certain premium features to go into those versions to provide enough value to be worth the price.

注意:我们需要以某种方式确保 Chocolatey 社区的长寿,那就是拥有一个 FOSSium(免费增值)模型。专业版每月 8 美元(每年 96 美元),比每月外出就餐花费更少,为您提供一些很棒的功能,并确保社区基础设施继续提供优质服务和改进。当您使用免费服务(社区存储库,又名https://chocolatey.org/packages)时,提供该服务不是免费的。因此,我们选择某些高级功能加入这些版本,以提供物超所值的价值。

回答by Matt Grundy

You could move the Chocolatey directory to another location then create a hard symbolic link from the default location - see The Complete Guide to Creating Symbolic Links (AKA Symlinks) on Windows.

您可以将 Chocolatey 目录移动到另一个位置,然后从默认位置创建一个硬符号链接 - 请参阅在 Windows 上创建符号链接(AKA 符号链接)的完整指南

I.e. mklink /J C:/ProgramData/chocolatey D:/my/new/location

IE mklink /J C:/ProgramData/chocolatey D:/my/new/location

But be sure to create the usual backups, restore points, etc. before doing anything.

但在做任何事情之前,一定要创建常用的备份、还原点等。

回答by quetzalcoatl

I've found another simple trick - install choco as usual, and right after installation move the c:\programdata\chocolateydirectory anywhere you like, and then update ChocolateyInstallenvironment variable and also update PATHenvironment variable so choco's \bin subfolder is found after moving it.

我发现了另一个简单的技巧 - 像往常一样安装 choco,安装后立即将c:\programdata\chocolatey目录移动到您喜欢的任何位置,然后更新ChocolateyInstall环境变量并更新PATH环境变量,以便在移动后找到 choco 的 \bin 子文件夹。

Of course, I don't know if it fine with any other packages, but I just installed 7zip and docker-machine with no problems, so seems to work.

当然,我不知道它是否适用于任何其他软件包,但我刚刚安装了 7zip 和 docker-machine,没有任何问题,所以似乎可以工作。

回答by antonio

For an MSI package (which is most often the case in Windows) use:

对于 MSI 包(在 Windows 中最常见的情况)使用:

choco install package-name  --% -ia INSTALLDIR="c:\intall\path"

To see whether the package is an MSI one, on the Chocolatey package page, under Files, look for chocolateyInstall.ps1and then look for:

要查看软件包是否为 MSI 软件包,请在 Chocolatey 软件包页面上的Files下查找chocolateyInstall.ps1,然后查找:

fileType = 'msi'

It was tested with Strawberry Perl.

它用Strawberry Perl进行了测试。

Of course, you can always use the paid chocolate and benefit from the ubiquitous install switch.

当然,您始终可以使用付费巧克力并从无处不在的安装开关中受益。

回答by Hazz22

It looks like Chocolatey has now created a ubiquitous switch:

看起来 Chocolatey 现在已经创建了一个无处不在的开关:

Ubiquitous Install Directory Option (Licensed Editions Only)

无处不在的安装目录选项(仅限许可版本)

I've not had chance to use this personally, but it looks like this would do the trick. If a little manual per application.

我没有机会亲自使用它,但看起来这可以解决问题。如果每个应用程序有一点手册。

回答by geisterfurz007

Adding to @antonio's answerI wanted to put my findings on other cases for setting the installation directory.

添加到@antonio 的答案中,我想将我的发现放在其他情况下以设置安装目录。

For fileType = 'exe'there seem to be two types of installers which you can tell apart with the given silentArgs(also in the chocolateyInstall.ps1).

因为fileType = 'exe'似乎有两种类型的安装程序,您可以通过给定的silentArgs(也在 )中区分它们chocolateyInstall.ps1

So far I found /Sas silentArgs and some longer stuff starting with /VERYSILENT /NORESTART(which seems to be an InnoSetup installer).

到目前为止,我发现/S作为silentArgs 和一些更长的东西开始/VERYSILENT /NORESTART(这似乎是一个InnoSetup 安装程序)。

  • /S: After testing I found this to be working (7zip as example):
    choco install 7zip.install -y --ia "/D\=D:\Destination\"(Note: This also triggers debugging output. If you have a solution that doesn't, please tell me!)
  • /VERYSILENT /NORESTART ...: According to the InnoSetup Installer CLI docsthe switch should be /DIR=<path>and it seems to work like this: choco install pdftk --ia="/DIR=D:\\Tool\\PDFTk".
  • /S:经过测试,我发现这是有效的(以 7zip 为例):(
    choco install 7zip.install -y --ia "/D\=D:\Destination\"注意:这也会触发调试输出。如果您有没有的解决方案,请告诉我!)
  • /VERYSILENT /NORESTART ...:根据InnoSetup安装CLI文档的开关应该是/DIR=<path>,它似乎像这样的工作:choco install pdftk --ia="/DIR=D:\\Tool\\PDFTk"

A lot of installers also don't use any of the above. VirtualBox for example expects certain installation arguments, the jdk8 package has params to set a directory that way etc. If you cannot match the silentArgsand fileTypewith the above you will have to do a little research.
For VirtualBox I ran the installer with /?and got a popup explaining the parameters that could be added.
For Mozilla Firefox I found a community post that explained what flags and switches were allowed for the installer. Unfortunately you have to resupply the ini file for updates every time making it a bit tedious.

许多安装程序也不使用上述任何一种。例如,VirtualBox 需要某些安装参数,jdk8 包具有以这种方式设置目录的参数等。如果您无法将silentArgsfileType与上述内容匹配,您将不得不做一些研究。
对于 VirtualBox,我运行安装程序/?并弹出一个解释可以添加的参数的弹出窗口。
对于 Mozilla Firefox,我找到了一篇社区帖子,其中解释了安装程序允许使用哪些标志和开关。不幸的是,您每次都必须重新提供 ini 文件以进行更新,这有点乏味。

Now if you primarily use chocolatey to easily update your applications automatically and install them without manually looking for download links and cluttering your download folder with .msi, .exe and .zip files, you can simply add the chocolatey flag --notsilent(or --not-silent) to have the installer run normally with all the options you could normally provide to the UI as well. In most cases they are then also used for updates.

现在,如果您主要使用 Chocolatey 来轻松地自动更新您的应用程序并安装它们,而无需手动查找下载链接和用 .msi、.exe 和 .zip 文件弄乱您的下载文件夹,您只需添加 Chocolatey 标志--notsilent(或--not-silent)即可获得安装程序使用您通常可以提供给 UI 的所有选项正常运行。在大多数情况下,它们也用于更新。

回答by vii

Summarized and corrected solution (incl. convenience script)

总结和更正的解决方案(包括便利脚本)

For the free version you have to pass the directory as an addtional input argument:

对于免费版本,你必须通过该目录作为一个addtionalNPUT一个rgument:

choco install theapp -y --ia "folder switch"



Challenge is that the switch differs from installer to installer.


挑战在于开关因安装者而异。

Proceeding to determine the installer

继续确定安装程序

  1. Go to the chocolatey package repoand search for your app
  2. Scroll down to "List Files" and open tools\chocolateyInstall.ps1. If there is no such file go back to search an use the "... .installer" version of the app.
  3. Search for fileType = exe. This was the case for most of my tested apps (see below). If it's the case search for silentArgs. If there is a:

    • /S: use --ia "/D=C:\new\path. Note: single backslashes, double backslashes didn't work for me. Also nobackslash before the =sign, gave me also an error.
    • /VERYSILENT: use --ia /DIR=C:\new\path. The verysilent switch belongs to the InnoSetup Installer.
    • something else: google "app silent install", determine the path switch and enter accordingly: --ia "..."
  4. fileType = msi: use --ia INSTALLDIR="C:\new\path"(I did not test this)

  1. 转到Chocolatey package repo并搜索您的应用程序
  2. 向下滚动到“列出文件”并打开tools\chocolateyInstall.ps1. 如果没有这样的文件,请返回搜索使用“....installer”版本的应用程序。
  3. 搜索fileType = exe。我的大多数测试应用程序都是这种情况(见下文)。如果是这种情况,请搜索silentArgs. 如果有:

    • /S: 使用--ia "/D=C:\new\path。注意:单反斜杠,双反斜杠对我不起作用。标志前也没有反斜杠=,也给了我一个错误。
    • /VERYSILENT: 使用--ia /DIR=C:\new\path。verysilent 开关属于 InnoSetup 安装程序。
    • something else:谷歌“应用程序静默安装”,确定路径开关并相应输入: --ia "..."
  4. fileType = msi: 使用--ia INSTALLDIR="C:\new\path"(我没有测试这个)

Backup solution

备份方案

Do a non-silent installment: choco install theapp --notsilent

做一个非静音分期付款: choco install theapp --notsilent

Convenience script

方便脚本

I wrote a powershell script which either installs apps in their default location or to a new one (provided by you). Applications are provided as a dictionary containing package-nameas keyand optional input argumentsas value. Be aware of the single and double quotation marks.

我写了一个 powershell 脚本,它要么在默认位置安装应用程序,要么安装到一个新的(由你提供)。应用程序以包含package-nameaskey和可选input argumentsas的字典形式提供value。注意单引号和双引号。

# --------------------------------------------------------------
# If installation should be in specific path, then provide it as value in the Dict / Hash table.
# Additional choco installer switches have to be set after the path.

$packToInstall= @{
    notepadplusplus=''; 
    vlc=''; # Install Dir can only be set via registry
    irfanview='';
    irfanviewplugins='';
    teamviewer='/D=D:\Programme\choco\TeamViewer"';
    vscode='"/DIR=D:\Programme\choco\vsCode" /NoDesktopIcon /NoQuicklaunchIcon';
    'cpu-z.install'='"/DIR=D:\Programme\choco\cpu-z" ';
} 
# --------------------------------------------------------------


# -------------- Script Start ----------------------------------

ForEach($key in $packToInstall.Keys){
    if ($packToInstall[$key]) { 
        choco install $key -y --ia $packToInstall[$key]   
    } 
    else {
        # Default installer
        choco install $key -y  
    }
}

Save as script.ps1 and run as admin. If the execution policies trouble you: PowerShell.exe -ExecutionPolicy UnRestricted -File .\script.ps1

另存为 script.ps1 并以管理员身份运行。如果执行政策困扰您:PowerShell.exe -ExecutionPolicy UnRestricted -File .\script.ps1



Remarks to other comments

对其他评论的评论

(I cannot comment directly because of my score, sorry)

(因为我的分数,我不能直接评论,抱歉)

  • @geisterfurz007Thank you for the manual.
  • @quetzalcoatlThis did not work for me since applications are not installed inside the chocolatey folder. Your solution moves the chocolatey binaries, package installation is still default.
  • @geisterfurz007感谢您的手册。
  • @quetzalcoatl这对我不起作用,因为应用程序没有安装在巧克力文件夹中。您的解决方案移动了巧克力二进制文件,包安装仍然是默认的。