Search code examples
rubyinstallationchocolateyruby-development-kit

How do I override the Ruby and Ruby DevKit installdir with Chocolatey?


I am somewhat new to chocolatey, having installed a few packages in the past on Windows 8, and I have come to like it.

I have noticed that chocolatey installs the packages in the default Windows program directory (i.e. "Program Files x86" or so). Maybe there is more to that that I am missing.

For the specific case of Ruby 2.1.5 and Ruby DevKit, I have a couple of questions:

  • How can I ensure I install the x64 versions of Ruby, and Ruby DevKit using chocolatey?
  • How can I set a custom installation directory from chocolatey?

I know there is some information about changing the install directory, but the arguments syntax are dependent on the install system used (if any) by the specific package being installed, in this case, Ruby & Ruby DevKit. I am yet to find what would be the CLI installation string for ruby and ruby devkit on windows. Any help is greatly appreciated. Thanks


Solution

  • Forewarning

    Parts of Ruby, coming from *nix, do not like spaces. Gems is one of them. This is not a Chocolatey thing, just an FYI in case you DO run into issues once you put it into Program Files. It likely won't work there, so if you run into problems, move it somewhere else.

    The installer also doesn't really update permissions if I recall correctly, so you are on your own to make sure your permissions are good so you can run it e.g. Program Files is Administrators writeable only, which you won't have unless you are running an administrative prompt (this is UAC, it removes you from the Administrators group in non-elevated processes).

    Guarantee x64?

    If you are on a 64-bit system and a package has x64 urls in it, you will get the 64-bit version of that software unless you specifically use -x86 to force the 32-bit version.

    • Looking at Ruby 2.1.5 package files - we see the chocolateyInstall.ps1 has this line (note the $url64, so we are good):

    Install-ChocolateyPackage "$packageId" 'exe' "$silentArgs" "$url" "$url64" -checksum $checksum -checksum64 $checksum64

    • Looking at Ruby2.DevKit package files - wee the chocolateyInstall.ps1 has this line (again using the x64 url):

    Get-ChocolateyWebFile 'ruby2.devkit' "$file" -url "$url" -url64bit "$url64" -checksum "$checksum" -checksum64 "$checksum64" -checksumType "$checksumType"

    Customize Install Folder

    Usually you would pass the native switch for changing the directory through installargs. However these packages, due to the known issues above, use Chocolatey's Get-BinRoot to determine where to install themselves.

    Chocolatey's Get-BinRoot

    Get-BinRoot uses an environment variable named ChocolateyBinRoot (set by default to $env:SystemDrive\tools) to determine where to put certain software that doesn't really qualify for Program Files. You can set that where ever you want, including Program Files folders and it will use that location instead.

    Installing Ruby and DevKit for v2

    • choco install ruby -version 2.1.5
    • If in cmd.exe refreshenv otherwise close and reopen shell.
    • choco install ruby2.devkit (note the ruby2)
    • Check the config.yml in the DevKit folder to see if it picked up the ruby installation, otherwise set it and run ruby dk.rb install (you may need force) in the devkit folder to install it into ruby. For more info, please see DevKit.
    • If in cmd.exe refreshenv otherwise close and reopen shell.
    • Now I'd like to say you can install gems, but you still need to deal with updating the ssl certificate for rubygems.org. I have an example on vagrant-windows-puppet.
    • Done.