Skip to content

Instantly share code, notes, and snippets.

@bronson
Created October 10, 2011 17:45
Show Gist options
  • Save bronson/1275927 to your computer and use it in GitHub Desktop.
Save bronson/1275927 to your computer and use it in GitHub Desktop.
Rig to demonstrate my problem using rbenv exec.

This is a quick rig to demonstrate my problem using rbenv exec.

Run:

cd parent
ruby test.rb
  • The parent should run on Ruby 1.9.2-p290
  • It should then fork a child that runs on system ruby
  • It then tries again setting RBENV_VERSION=system too.

Expected: Parent and child should run on different versions of Ruby.

Actual: The version of Ruby never changes.

I think the .rbenv-version files are set up correctly because:

$ cd parent
$ rbenv local
1.9.2-p290
$ cd ../child
$ rbenv local
system
$ rbenv shell
rbenv: no shell-specific version configured

Output

Output on my system

$ cd parent
$ ruby test.rb

in parent, .rbenv-version file specifies 1.9.2-p290
    version=1.9.2: /home/bronson/.rbenv/versions/1.9.2-p290/bin/ruby
    executing child...

in child, .rbenv-version file specifies system
    version=1.9.2: /home/bronson/.rbenv/versions/1.9.2-p290/bin/ruby
    cwd is /tmp/1275927/child

back in parent, .rbenv-version file specifies 1.9.2-p290
    version=1.9.2: /home/bronson/.rbenv/versions/1.9.2-p290/bin/ruby
    executing child using RBENV_VERSION=system too...

in child, .rbenv-version file specifies system
    version=1.9.2: /home/bronson/.rbenv/versions/1.9.2-p290/bin/ruby
    cwd is /tmp/1275927/child
#!/usr/bin/env ruby
puts "in child, .rbenv-version file specifies system"
puts " version=#{RUBY_VERSION}: " + `which ruby`
puts " cwd is " + Dir.pwd
#!/usr/bin/env ruby
puts "in parent, .rbenv-version file specifies 1.9.2-p290"
puts " version=#{RUBY_VERSION}: " + `which ruby`
puts " executing child..."
puts
Dir.chdir "../child" do
system "ruby test.rb"
end
puts
puts "back in parent, .rbenv-version file specifies 1.9.2-p290"
puts " version=#{RUBY_VERSION}: " + `which ruby`
puts " executing child using RBENV_VERSION=system too..."
puts
Dir.chdir "../child" do
ENV['RBENV_VERSION'] = 'system';
system "ruby test.rb"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment