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

前端 未结 8 844
半阙折子戏
半阙折子戏 2021-01-30 16:19

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 program

8条回答
  •  心在旅途
    2021-01-30 16:45

    Summarized and corrected solution (incl. convenience script)

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

    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 repo and 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 no backslash 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)

    Backup solution

    Do a non-silent installment: 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-name as key and optional input arguments as value. Be aware of the single and double quotation marks.

    # --------------------------------------------------------------
    # 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


    Remarks to other comments

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

    • @geisterfurz007 Thank you for the manual.
    • @quetzalcoatl This 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.

提交回复
热议问题