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

前端 未结 8 800
半阙折子戏
半阙折子戏 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:44

    The accepted answer hints at this option already, so I'm only posting for the sake of completeness:

    Change the default Program Files directory with regedit

    While SSDs have gotten bigger and cheaper in recent years, there are still some niche use cases where you want to keep a Windows install on a separate, smaller partition and software on a different, bigger partition.

    1. Press win + R and type regedit
    2. Locate this key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
    3. Change ProgramFilesDir and ProgramFilesDir (x64) from C:\ProgramFiles to [your drive]:\Program Files

    Citing my sources: this answer but longer.

    Important notes

    Chocolatey will, in general, respect this — but there's a few caveats with that method that need to be mentioned:

    • Some programs/installers don't respect ProgramFilesDir registry keys. For example, Audacity still installed to C: (despite — in my case, at least — ProgramFilesDir is F:\Program Files, but chocolatey made an assumption that it's installed to F: when making the shortcuts and start menu entries).
    • This breaks NVIDIA GeForce Experience. There may also be other side effects, but I haven't found them yet.
    • You need to change ProgramFilesDir registry keys before installing anything with chocolatey, otherwise some scripts, packages, or programs might be broken (for example, I had to reinstall the chocolateygui package)

    Side note: this answer operates under assumption that "how do I set chocolatey to install applications onto another drive" means "how do I set chocolatey to install application to the same drive where I've installed most of my other software."

    0 讨论(0)
  • 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.
    0 讨论(0)
  • 2021-01-30 16:46

    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.

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

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

    0 讨论(0)
  • 2021-01-30 16:47

    It looks like Chocolatey has now created a ubiquitous switch:

    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.

    0 讨论(0)
  • 2021-01-30 16:49

    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.

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

    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).

    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.

    0 讨论(0)
  • 2021-01-30 16:49

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

    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.

    0 讨论(0)
提交回复
热议问题