Our Ruby packages install binaries as ruby26, ruby25, irb26, irb25, 
etc. to allow concurrent installation and each package's MESSAGE 
says to setup symlinks to have one default ruby, irb, etc.

In practice this doesn't work very well when one has multiple Rails 
or other Ruby projects that require different versions of Ruby to be 
used, at least without modifying lots of shebang lines, cron tasks, 
and process management tools to call a specific version of ruby, 
rake, bundler, etc. for every project.

This is helped on other platforms with things like rbenv and chruby 
and the ".ruby-version" file which is added to each project's root 
directory and indicates which version of ruby and other tools should 
be used for it:

https://gist.github.com/fnichol/1912050

But rbenv and chruby usually require custom-installed versions of 
Ruby in one's home directory, they don't otherwise work with our 
nice existing Ruby packages, or they require integration with each 
user's shell to override $PATH.

I wrote this small script to behave like those systems by being the 
target of the default symlinks for ruby, erb, irb, rdoc, ri, rake, 
gem, bundle, and bundler.  The script looks at the .ruby-version 
file in the current directory (falling back on /etc/ruby-version) 
and runs the appropriate ruby26, ruby25, irb26, irb25, etc. listed 
in the file.  Only the major and minor numbers are honored, since we 
only have one Ruby package per major/minor anyway.

If there is no .ruby-version file found in the current directory and 
no system-wide /etc/ruby-version file, it just uses the highest 
version installed.

So in summary:

    # pkg_add ruby-shims ruby-2.5.6 ruby-2.6.4

    $ ruby -v
    ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-openbsd]
    $ irb -v
    irb 1.0.0 (2018-12-18)

    $ echo 2.5 > .ruby-version
    $ ruby -v
    ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-openbsd]
    $ irb -v
    irb 0.9.6(09/06/30)

Attachment: ruby-shims.tar.gz
Description: Binary data

Reply via email to