Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rbenv: multiple instances of SAME ruby

I have two scripts which require the same version of Ruby. However, each script also requires a DIFFERENT version of a gem (nokogiri). One of the scripts will run with both versions of nokogiri (1.6.2.1 and 1.6.1). However the other script will ONLY run with version 1.6.1; and if 1.6.2.1 is installed, the script will not execute normally.

I know how to install multiple versions of Ruby with rbenv. But is it possible to install multiple instances of the SAME version of Ruby (2.1.2)? If so, how?

like image 420
tSquirrel Avatar asked Jul 03 '14 19:07

tSquirrel


2 Answers

Make a local copy of a ruby-installer definition file using a custom name.

$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-nokogiri161

Install this as a custom definition file, no edits required.

$ rbenv install ./2.1.5-nokogiri161

Now you have a ruby version with a custom name and you can install custom gems on it.

$ rbenv shell 2.1.5-nokogiri161
$ gem install nokogiri -v 1.6.1

This is also useful for installing ruby versions with custom build flags. For example, a debug build with no compiler optimizations.

$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-debug
$ RUBY_CONFIGURE_OPTS="optflags=-O0" rbenv install ./2.1.5-debug
$ rbenv shell 2.1.5-debug
like image 66
ender672 Avatar answered Sep 27 '22 23:09

ender672


I see two options:

  1. You could have different Gemfiles and let bundler take care of setting the right gem-version. If the scripts are in different directories, it should be no problem.

  2. You could use rbenv-gemset to have separate gem-environments

There are undoubtly more, but those two seem the easiest for your setup.

like image 35
kronn Avatar answered Sep 28 '22 01:09

kronn