52

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.

Any ideas?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Hazz22
  • 790
  • 1
  • 7
  • 14
  • I found something good on this post : https://superuser.com/questions/693466/how-do-i-install-chocolatey-in-a-different-location-than-standard-say-even-on. @Thor answer is helpful. – Willy satrio nugroho Feb 15 '20 at 08:39

8 Answers8

25

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
ferventcoder
  • 10,640
  • 2
  • 51
  • 83
  • 1
    Thanks for the information. I'll take a look at the switch. Hope the ubiquitous switch gets implemented. – Hazz22 Nov 05 '13 at 22:03
  • 1
    Oh we plan to get there someday – ferventcoder Nov 08 '13 at 20:43
  • 18
    Without jumping onto the "Are we there yet? Are we there yet?" bandwagon, is there an ETA on this feature? I know it's far from simple, but global change on install directory (IE: D:\Programs) would be sweet. That would be icing on the... chocolatey... cake... – WernerCD Jul 23 '14 at 19:04
  • @WernerCD we have some fundamental design issues to address first. This is on the roadmap, it's a highly requested feature. I look for it to be in a v2 as v1 needs to address all of the design difficulties and get those fixed first. – ferventcoder Jul 24 '14 at 15:19
  • @ferventcoder What about binary packages, scripts, and commandline tools that are just download and no installer? Is there a specific -installArgs parameter to pass to the Chocolatey downloader? – Ryan Bemrose Sep 20 '14 at 18:03
  • @RyanBemrose What would you like to pass? – ferventcoder Sep 23 '14 at 01:13
  • After already spending 15+ minutes on this, i cant seem to find a foolproof way to google how to know what programs use what, for e.g. im trying to install docker to the D drive, and this little comment is now my only hope before i give up. Is there any good resources on installer types, or a way a user who doesnt really need-to-know much about install types to find this kind of info out? Note, all i see is .zip, .zip, .zip in the docker install, that doesnt appear to be a clue either. Do i need to dig into the ProgramData dir maybe? – blamb Mar 29 '17 at 19:28
  • @blamb all paid versions of Chocolatey support the ubiquitous install directory switch. And you are correct - changing install directory in the unattended arguments without licensed editions of Chocolatey licensed is one of the most painful things to do on Windows due to the 20+ installer types. Chocolatey's ubiquitous directory switch is not perfect yet but it's always getting better. – ferventcoder Mar 30 '17 at 00:02
  • It also doesn't help that the docs on the GettingStarted page ("Overriding default install directory [...]") are either inaccurate or out of date. Even copy/paste provided there is doing nothing. `choco install libreoffice-fresh -ia "INSTALLDIR=""D:\Program Files\LibreOffice"""` (from that page, just with D:, run in cmd.exe) => `The install of libreoffice-fresh was successful. Software installed to 'C:\Program Files\LibreOffice\'`. And while I understand the reason for the paid versions, it's hard to justify buying it without being able to test it properly. Even your codebase uses TARGETDIR ;) – Tarulia Sep 07 '18 at 01:40
  • Adding to my comment above, this seems to be more of an issue with that specific package, because I don't seem to be able to change the installdir with straight `msiexec` either (probably should have tried that earlier, would have saved me a lot of headaches, it works fine with another package). Anyway, I'm wondering if/how the ubiquitous switch deals with that? – Tarulia Sep 07 '18 at 02:24
  • 1
    So it's definitely software dependent @Tarulia - you have to already know the silent install options that will work to be able to pass it in. In the licensed edition, Chocolatey will detect the type of installer, then act on what it has - MSIs use "TARGETDIR" by default, but typically most tools that make MSIs use "INSTALLDIR". Chocolatey will look for different options that might be used and end up using a default. Even at the end of all of this, Chocolatey is currently beholden to the underlying software installer - so it would need to support changing directories. – ferventcoder Sep 17 '18 at 19:23
12

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Matt Grundy
  • 121
  • 1
  • 2
  • 1
    Simple. Effective. Works. – quetzalcoatl Jul 10 '17 at 17:54
  • 2
    In case it helps, with Windows Version 10.0.17134.112, I had to use `mklink /J "C:/ProgramData/chocolatey" D:/my/new/location` (note the added quotation marks). My second directory needed them anyway, so I don't know whether it'll always want them there. Hope it helps someone. – BaldEagle Jun 27 '18 at 18:59
  • 1
    In Powershell the quotation mark is needed like @BaldEagle solution. In CMD the quotation mark doesn't necessary. – Willy satrio nugroho Feb 15 '20 at 07:57
11

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.

quetzalcoatl
  • 27,938
  • 8
  • 58
  • 94
  • Nice workaround; thanks. While I understand how to implement the solution, how does this work? – BaldEagle Jun 27 '18 at 15:23
  • 1
    @BaldEagle: when you install any application anywhere, later, something may want to find out if and where you had installed it. If it was a MSI-based installer, you could as the Windows-Installer platform, but Choco does not use it. Choco could simply hardcode the path to be "C:\choco" but we've got 201x now and pretty no sane developer does it. Then, we've got chicken-and-egg problem: we need to store the installation-location information somewhere, so someone can inspect it later, but then, this 'somewhere' has to be universally available and not change in future. Registry is one option... – quetzalcoatl Jun 27 '18 at 19:12
  • 1
    @BaldEagle: ..but it really gets cluttered much and it may be a little problematic if there are multiple installation for some reason. And it will not work on Linux/etc, as there is no registry there. For that reason, many apps/platforms/utilities store such information in "environment variables" that are available on pretty much all contemporary OS'es. EnvVars can be managed on many layers - system default, user, process, etc - and using them to store simple string like path is dead easy. Java does it. Visual Studio does it. So Choco does it too. Run `set` in console and see all other things. – quetzalcoatl Jun 27 '18 at 19:15
  • 1
    @BaldEagle: so, we've got the magic env-var. Anytime anyone wants to find Choco, he just looks into that magic env-var, provided that he cares to support Choco. Your OS does not care about Choco, Java, or whatever, nor it cares about their custom env-vars. That's yet another user application. Having just the Choco's envvar won't help in finding and running `choco.exe`, you'd still need to write whole path, just because OS does not care about Choco's special env-variable. But, the OS looks into PATH. Adding Choco's path to PATH allows you to write just `choco`. And that's pretty much all to it. – quetzalcoatl Jun 27 '18 at 19:20
7

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

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.ps1 and then look for:

fileType = 'msi'

It was tested with Strawberry Perl.

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
antonio
  • 9,285
  • 10
  • 59
  • 113
  • Can you elaborate on what the `--%` switch does? I don't seem to be able to find documentation on that. – Tarulia Sep 07 '18 at 02:11
  • 1
    @Tarulia From the Choco help "In PowerShell.exe if you are on version v3+, you can try `--%` before `-ia` to just pass the args through as is, which means it should not require any special workarounds." – Ben Murden Mar 05 '19 at 04:40
  • This solution doesn't seem to work. No changes in the installation script. Package is installed in the default directory on `C:` drive. Choco `0.10.15` – VELFR Jan 30 '20 at 18:38
  • 1
    Also, currently `--ia` option is documented with two dashes – VELFR Jan 30 '20 at 18:46
4

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Hazz22
  • 790
  • 1
  • 7
  • 14
  • 7
    Huh. *Install Directory Override **(Licensed Editions Only)***. So, to override directory, you need to pay **$8/month**. – Athari Jun 19 '16 at 15:28
  • 3
    We need to ensure the longevity of the Chocolatey community somehow, and that is to have a FOSSium (Freemium) model. That $8/month gets you some awesome features and ensures that the community infrastructure continues to stick around and improve. While you are using a free service, it is not free to provide that service. – ferventcoder Aug 29 '16 at 17:15
3

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"


The 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 and use the ".installer" version.
  3. Search for fileType = exe. Most of my tested apps had this extension. 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, as suggested in other comments.
  • /VERYSILENT: use --ia /DIR=C:\new\path. The verysilent switch belongs to the InnoSetup Installer.
  • something else: search "app silent install" on google, determine the path switch and enter it accordingly: --ia "..."
  1. fileType = msi: use --ia INSTALLDIR="C:\new\path" (I did not test this)

Fallback solution

Do a non-silent installment and specify the path in the ui: choco install theapp --notsilent

Convenience script

I created a Powershell script which allows to install common apps (vlc, VS Code, python, git, Chrome...) with custom parameters, incl. folders:

https://github.com/vii33/ChocoVanillaPackage


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, the package installation is still done in the default folder.
vii
  • 83
  • 7
2

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

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

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

  • /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 docs the switch should be /DIR=<path> and it seems to work like this: 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 silentArgs and fileType with 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.

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.

geisterfurz007
  • 3,390
  • 5
  • 29
  • 46
1

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

Tamius Han
  • 90
  • 1
  • 7