RVM Autolibs: Automatic Dependency Management and Ruby 2.0
- Transfer
The past month marked the beginning of a new milestone for rubists - the release of Ruby 2.0.0. With it, updated RubyGems and new dependencies, including OpenSSL. Previously, RVM did almost nothing to resolve dependencies, installing LibYAML instead, since it was needed for RubyGems to function. The situation has changed with the advent of OpenSSL, as this is a big dependency. For Ruby 2.0.0-rc, RVM used to install OpenSSL. Compiling OpenSSL is not an easy task, however, using LibYAML.
New approach
To make it all work, RVM takes a new approach. Now, when installing the necessary libraries, it works in tandem with the system package manager. This is not an easy task, since different systems have different names for packages, some of them are available by default, and some are not available at all!It's easy when it's easy
It is very simple to use an existing package manager on any of the systems. Troubles begin when the system does not have a default package manager, as is the case with OSX. There are many package managers, and none of them are popular enough to become the de facto standard. Given this, RVM needs to find the installed package manager or install it if it is not available.Sensitive Defaults
When autolibs was first added, RVM thought the user wanted all the work done for him. However, reality has shown that some users think differently and prefer to install dependencies manually. A compromise was needed to satisfy everyone. As a result, RVM will determine the available libraries and fail if they are not available. Users now have the option to switch between different modes, such as “ do everything for me ” and “ I will do it myself .”Do it all for me
Users who want to automatically install libraries can use autolibs mode 4 aka. enable. This will tell RVM to find the package manager (and install one if necessary), install all the dependencies, and finally use them to compile. If the package manager is not available (on OS X), Homebrew will be installed. However, users can also specify which manager will be installed with the autolibs osx_port, osx_fink and smf modes. The smf manager is for the lesser-known RailsInstaller SM framework. For systems with a system package manager installed, mode 4 is identical to mode 3, which installs the missing packages.
I do it myself
For users who do not want RVM to do everything for them, there are two suitable modes. Mode 1 allows users to tell RVM to take libraries and simply throw an error if they are not available. In cases where even an automatic availability check is not needed, you can turn it off using mode 0. However, there is a nuance. Given that the code is becoming more dynamic, there is no longer a list to show what is required. This means that some libraries will be selected depending on the state of the system.A couple of tricks
To install RVM along with Ruby, Ruby on Rails and the necessary libraries (aka. RailsInstaller for the poor): \curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enable
To use rvm in development, where sudo requires special handling, as is the case with capistrano:
task :install_requirements do
sudo “rvm --autolibs=4 requirements #{rvm_ruby_string}”
end
task :install_ruby do
run “rvm --autolibs=1 install #{rvm_ruby_string}”
end
More information about autolibs is available at rvm.io/rvm/autolibs .