basecamp / pow

Zero-configuration Rack server for Mac OS X
http://pow.cx/
MIT License
3.41k stars 259 forks source link

.ruby-version in parent dir leads to incorrect rbenv Ruby #363

Open tilsammans opened 11 years ago

tilsammans commented 11 years ago

My apps live in ~/Rails/ and each have a .ruby-version. Rails server runs fine. But Pow always wants to load the Ruby specified in the parent dir a.k.a. my home dir: ~/.ruby-version.

When I remove ~/.ruby-version, Pow correctly loads rbenv from the Rails application directory and the correct Ruby. So there's a path lookup going haywire somewhere. The .ruby-version in the application directory should always win, IMO.

Mac OS X 10.8.3 with zsh and Oh-My-Zsh.

terrafied commented 11 years ago

I found this gist, which sort of forces the issue locally by updating your project's .powrc with the following:

if [ -f "$rvm_path/scripts/rvm" ]; then
  source "$rvm_path/scripts/rvm"

  if [ -f ".rvmrc" ]; then
    source ".rvmrc"
  fi

  if [ -f ".ruby-version" ]; then
    rvm use `cat .ruby-version` 
  fi

  if [ -f ".ruby-gemset" ]; then
    rvm gemset use --create `cat .ruby-gemset`
  fi
fi
JunichiIto commented 11 years ago

I got the same issue and had to delete .ruby-version in my home dir. Hope it would be fixed soon.

Emerson commented 11 years ago

I just hit this issue as well. Took me half a day to find this post.

guidobouman commented 11 years ago

It usually doesn't make a lot of sense to have a .ruby-version in your home dir, that's more or less what's the rbenv global is for.

I'll dig into it though. As nested projects should give the deepest .ruby-version precedence.

tadman commented 11 years ago

Just got hit with this particular issue. rbenv uses the deepest reference, and Pow seems to use the top-most, which is inconsistent.

It doesn't make sense to have it in your home directory, but if you've done a rbenv local x.x.x by accident there, you wouldn't notice, as your applications are still keyed correctly.

guidobouman commented 11 years ago

The way rbenv works is that it figures out the directory it's running in, and uses the corresponding Ruby version. Somehow rbenv believes that the home directory has precedence over the project directory...

Pow does not do anything to change this behaviour. This is because rbenv replicates native functionality in a really neat way. Simply put: Rbenv is in control of ruby versions at all times. (https://github.com/sstephenson/rbenv#understanding-path)

This error might be occurring because of the way the pow symlinking is set up. This would be a rbenv bug though, not a pow bug. @sstephenson, as author of both tools, what's your opinion?

jhubert commented 10 years ago

Just hit this as well after upgrading to OSX Mavericks. Wasted nearly half a day trying to figure it out. :-1:

tadman commented 10 years ago

What is especially confusing about this issue is running rails or rake test in the application directory will run the correct version of Ruby, the one specified for that particular application, but Pow will instead use the one defined in the home directory. If rbenv is in control, the way it's being engaged isn't the same as via the command-line.

This issue is really confusing as everything you do on the command line works, and everything you do through Pow is broken. Normally the two are in sync and it's possible to reproduce Pow loading problems with rails c.

ream88 commented 10 years ago

Bit me too!

regedarek commented 10 years ago

I have the same issue here. After fresh Mavericks install. Then rbenv using homebrew, installed 2.0.0p247. Also installed rbenv-bundler. And set .powconfig in root directory.

But pow can't recognise correct ruby version and throw:

LoadError: cannot load such file -- bundler/setup
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
~/Code/app/config/boot.rb:4:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
cardiogo(development)» gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [universal.x86_64-darwin13]
  - INSTALLATION DIRECTORY: /Users/rege/.gem
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/rege/.gem/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-13
  - GEM PATHS:
     - /Users/rege/.gem
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - https://rubygems.org/
guidobouman commented 10 years ago

@regedarek This might be a different issue. If you remove the .ruby-version in the parent directory of your application (or home directory), everything should work well.

If the problem is still occurring and you use zsh, check this out: https://github.com/37signals/pow/issues/202#issuecomment-21212967

regedarek commented 10 years ago

Hi, Thanks a lot. #202 (comment) solved with my issue.

colinyoung commented 10 years ago

This tripped me up for a long time! Still an issue in the current version.