Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't switch versions of ruby midstream (different processes) #720

Closed
ericpromislow opened this issue Apr 17, 2015 · 3 comments
Closed

Comments

@ericpromislow
Copy link

Using Bundler 1.6.2

I have two versions of ruby installed, 1.9.3 and 2.1.5. master.rb is started with bundle exec, and it declares "ruby '2.1.5'" in its gemfile, and has a .ruby-version file with contents '2.1.5'.

master.rb switches to the dir that houses slave.rb, which is still running 1.9.3(p-484). It has
a gemfile entry of "ruby '1.9.3'" and .ruby-version file with contents '1.9.3'.

If I try running bundle exec ruby --version from master.rb in slave.rb's dir, it complains that the Gemfile specifies 1.9.3, but it's running 2.1.5. I reproduced this with this small two-file example:

master.sh:

#!/bin/bash

export RBENV_VERSION=2.1.5
echo "Ruby in shell script: `ruby --version`"
echo "Now shell out, hoping for 1.9.3:"
ruby slave.rb

and slave.rb:

 system("bundle exec ruby --version")

The output is:

 Ruby in shell script: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
 Now shell out, hoping for 1.9.3:
 ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

While in my system I launch the master under bundle exec, I don't have to here to reproduce
the problem. It seems that just setting RBENV_VERSION and then running rbenv/libexec pushes
the 2.1.5 path to the top of the PATH as a sort of optimization, and I'm stuck with it when I try
to spawn children. I even passed a cleaned path as the first arg to system in slave.rb, but it didn't have an effect.

Is there a way to do this, or should we migrate all our components to the same version?

@dlee
Copy link

dlee commented Apr 29, 2015

I think I just ran into this bug. I think this is because the $RBENV_DIR env var is being set from the top-level ruby and leaking down into the subcommands, even if $RBENV_VERSION is being changed.

Can you try prepending rbenv shell --unset; RBENV_DIR= to the subcommand?

 system("rbenv shell --unset; RBENV_DIR= bundle exec ruby --version")

UPDATE: Both $RBENV_VERSION and $RBENV_DIR are leaking to children processes. Even though you can unset the $RBENV_VERSION using rbenv shell --unset, you still need to manually clear out $RBENV_DIR.

@jmiettinen
Copy link

I've also been bitten by this. This seems to be because rbenv works to keep the Ruby version the same. This is done by prepending the path of the selected Ruby to PATH as seen here.

@mislav
Copy link
Member

mislav commented Sep 11, 2015

This is unfortunately a known issue: #121

@mislav mislav closed this as completed Sep 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants