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
RBENV_VERSION ignored when shelling out from ruby #121
Comments
not sure if this still fixes issue rbenv#95 though.
That commit fixes this issue. Now I get the expected results:
Is it good enough to be merged? Or does issue #95 require the bin path to come before the shim path? I'd really like to find a good solution to this. Thanks! |
I mean, does the rbenv -S issue mentioned in #95 (#95 (comment)) require the bin path to come before the shim path? |
This is still an issue in 0.3.0. |
Your problem is that, when calling your script from However from ruby you're calling I don't know whether this is a bug, or how to solve it. It seems unsolvable from rbenv. If from a ruby process you want to shell out to rbenv, you would need to edit ENV['PATH'] first to restore it to the pristine state. |
Maybe rbenv should remove from imho that's bug. nothing should prevent running other version of ruby from ruby script. |
It's a common pitfall. You can clear the current env from a Ruby process like so: rbenv_root = `rbenv root 2>/dev/null`.chomp
unless rbenv_root.empty?
re = /^#{Regexp.escape rbenv_root}\/(versions|plugins|libexec)\b/
paths = ENV["PATH"].split(":")
paths.reject! {|p| p =~ re }
ENV["PATH"] = paths.join(":")
end |
I think it should be rbenv responsibility, not ruby programmer. |
True. I also don't think the above workaround is what users should be doing in the long run. However, that is what they need to do with the current version of rbenv (0.4). You can also put this plugin in # EXPERIMENTAL: clean up PATH of modifications made in rbenv.
# This DISABLES the feature added in 2a495dc for `ruby -S` compatibility.
path_without_rbenv() {
local result=""
local paths
IFS=: paths=($PATH)
for path in "${paths[@]}"; do
if ! [[ "$path" =~ "${RBENV_ROOT}/versions/" || \
"$path" =~ "${RBENV_ROOT}/plugins/" || \
"$path" == "${RBENV_ROOT}/libexec" ]]; then
result="${result}${path}:"
fi
done
echo "${result%:}"
}
exec() {
export PATH="$(path_without_rbenv)"
builtin exec "$@"
} |
+1 for this |
\o/ |
This is huge. Kick ass, Mislav. |
I tried mutating the PATH so that it uses the 'ruby' shim, but rbenv still doesn't use the version from .ruby-version in the current dir: Any ideas why?
|
@trogdoro Not sure what is happening, nor what's your use case. My general advice is to use |
Woops, forgot to blank out the RBENV_VERSION var. Adding "RBENV_VERSION"=>"" to the hash fixes it:
Thanks! |
Enables shelling out from a ruby process started with rbenv to a ruby process with a different RBENV_VERSION. Fixes rbenv#121 This removes the workaround created for rbenv#15 and solves `ruby -S` support by setting RUBYPATH. PATH is never changed. To illustrate how RUBYPATH changes in various configurations: PATH=~/bin:~/.rbenv/shims:/usr/bin:/bin RBENV_VERSION=1.8 ruby -S rake #=> executes ~/.rbenv/versions/1.8/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin RBENV_VERSION=2.0 ruby -S rake #=> executes ~/.rbenv/versions/2.0/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/2.0/bin:/usr/bin:/bin RBENV_VERSION=system ruby -S rake #=> executes /usr/bin/rake #=> RUBYPATH=~/bin:/rbenv_shims_were_here:/usr/bin:/bin RBENV_VERSION=1.8 ruby -S rake #=> executes ~/.rbenv/versions/1.8/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin
The fix of this was reverted in 95a039a so I'm reopening this. |
This shows that RBENV_VERSION works when executed from Perl but not from Ruby. In this example, global version is set to 1.9.2p290.
RBENV_VERSION should always work, shouldn't it?
The text was updated successfully, but these errors were encountered: