postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

GEMDEPS weirdness #298

Closed michaelrkn closed 9 years ago

michaelrkn commented 9 years ago

Hello! I'm using chruby 0.3.8 and rubygems 2.4.4. My .bash_profile looks like:

export PATH=/usr/local/bin:$PATH
source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh
export RUBYGEMS_GEMDEPS=-

If I run:

git clone https://github.com/epicodus/textbook
cd textbook

I get:

Unable to resolve dependency: 'rails (~> 4.0.4, ~> 4.0.4)' requires 'bundler (< 2.0, >= 1.3.0)'
You may need to `gem install -g` to install missing gems

Running gem install -g doesn't make the error go away.

But, deleting my .ruby-version file, or removing auto.sh from my .bash_profile, and manually switching to the correct version of Ruby, does make the error go away.

If this problem is really with rubygems, I can open an issue there.

Let me know if there's anything I can do help track down what's going on here!

michaelrkn commented 9 years ago

bump

havenwood commented 9 years ago

@marcosdsanchez This appears to be a Bundler issue. Typically with a Rails app you'd bundle then run in the context of that bundle by prefixing bundle exec to Rails commands. The #rubyonrails or or #bundler channels on IRC would be good places to get quick feedback. Or the #ruby and #ruby-lang channels are well populated and can usually point you in the right direction.

michaelrkn commented 9 years ago

Thanks for the reply, @havenwood. Are you familiar with the new feature introduced in RubyGems 2.2.0 that removes the need for bundle exec?

RubyGems can check for gem dependencies files (gem.deps.rb or Gemfile) when rubygems executables are started and uses the found dependencies. This means rake will work similar to bundle exec rake. To enable this set the RUBYGEMS_GEMDEPS environment variable to the location of your dependencies file.

To globally enable this new feature, you can add export RUBYGEMS_GEMDEPS=- to your .bash_profile.

Something in the way auto.sh works seems to not be playing nicely with RUBYGEMS_GEMDEPS, at least in some circumstances. If I remove auto.sh from my .bash_profile, I can run:

chruby 2.1
cd textbook/

And there are no errors. This makes me suspect the problem is something with auto.sh, but I can't figure out what it could be.

marcosdsanchez commented 9 years ago

@havenwood, I guess you don't want me involved here and you mistyped my username :) .

havenwood commented 9 years ago

@marcosdsanchez Oops, my Github autocompletion fail! Sorry about that.

havenwood commented 9 years ago

@michaelrkn I wasn't up to speed on export RUBYGEMS_GEMDEPS=- and misunderstood your intentions. Thanks for the explanation, I see what you mean now!

I'm able to reproduce the issue with bash and zsh, with or without sourcing auto.sh. It appears to be triggered when chruby_use() evals ruby to set RUBY_ENGINE, RUBY_VERSION and GEM_ROOT.

michaelrkn commented 9 years ago

Great! Let me know if there's anything else I can do to help sort the problem out.

postmodern commented 9 years ago

Checkout @havenwood's solution. We agreed that using typeset unset within the function to temporarily unset RUBYGEM_GEMDEPS was the safest solution.

michaelrkn commented 9 years ago

Hooray! Thanks :)

havenwood commented 9 years ago

While typeset unset or local unset both work as expected on bash 3 and zsh it appears upon further testing that unfortunately neither is portable to bash 4.