The mind is like a parachute. If it doesn't open, you're meat.

Ruby on Windows: Chocolatey time

12 Jun 2019

I have been steadily increasing my use of chocolatey for installation of toolchains on Windows.

There are still a few problems, e.g. not all packages allow setting an alternate installation directory etc., but these are problems we had with the original installers as well.

There are also some version pinning issues with some packages that seem to originate on the way chocolatey provides URLs to updated packages. These lead to failures if the version is pinned and the package gets updated.

Ruby and chocolatey

Since the 2.4 version, the RubyInstaller has switched to using the newer msys2 toolchain for C extension compilation which complicated the process of automating installation via the MSI installer.

Fortunately both msys2 and the newer RubyInstallaer are available as chocolatey packages.

Unfortunately there are still some hiccups.

You have to take care to place the msys2 path entry before the Git for Windows path entry. The git installer bundles a mingw version that will mess up gem installations if detected before msys2.

Same goes for the ChefDK path entry, only this time with ruby: ChefDK bundles a ruby distro and gem installations will go array if it is found first in the path.

Chef and chocolatey

My current infrastructure-as-code solution for turning Windows into a development environment is based on Chef and the windev cookbook (full disclosure: windev is maintained by yours truly, so doh!).

Chef provides a chocolatey_package resource and windev adds a configuration helper choco_packages for adding packages.

The following snippet will configure windev to install ruby on a windows machine:

  "PATH":"c:\\tools\\ruby\\bin;c:\\tools\\msys2;C:\\Program Files\\Git\\bin;C:\\ProgramData\\chocolatey\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\opscode\\chefdk\\embedded\\bin;"
"run_list": [

Unfortunately, there is a bug in the interaction between Chef and chocolatey (in the choco_package resource), specific to the msys2 installation.

The installation of msys2 will hang and fail with a timeout - though msys2 will have been correctly installed. Re-run Chef and everything continues normally.

Kinda defeats the main purpose of using it with Chef, but we still get to document in code how the environment is set up.

blog comments powered by Disqus