NOTE: I have fixed/hacked this problem in my environment (details below), but I would really like to understand what happened & provide a resource if this happens to others. Hopefully this is an OK use of Stack. :)
I'm going through Michael Hartl's Ruby on Rails Tutorial (2nd Edition), and I hit my first major snag today.
In chapter 3, section 3.6.1 "Eliminating Bundle Exec", I executed these commands to get Ruby Version Manager (RVM) to 'adjust' my path for all projects such that I can stop typing bundle exec so often:
$ rvm get head && rvm reload
$ chmod +x $rvm_path/hooks/after_cd_bundler
$ cd /path/to/project
$ bundle install --binstubs=./bundler_stubs
..and voila! I can no longer run bundle, rvm, or many other common functions (I'm still new to Rails, so I don't know what relationship or origins these commands share). I did a full reboot because I come from Windows, and that's just what you do when shit gets funky, but the issue persisted! BLLARG!
The error is the same for bundle, rvm, etc:
-bash: rvm: command not found
(NOTE: Also around this time, I modified xcode-select -switch from /Developer to some other longer, crazier path - see this link for details if you think this might play a role)
I did some digging, and found that this may have something to do with my $PATH, so here is my env $PATH, if it matters:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
The PATH seemed wrong - there was supposed to be some RVM stuff in there, or some bundler stuff in there - that was the point of the change! - so I did some more digging, and discovered that my file system was still intact and looking good (RVM still installed, Gemfile still correct, etc), and yet in my Terminal session the version of Ruby was old (v1.8.7), and Rails wasn't even installed, so it started to seem more like session- or RVM-specific problem.
Did some more digging and found that if I MANUALLY ran the following commands (from ~/.bash_login) in Terminal, everything worked:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
YES!
When I closed & re-opened Terminal, the problem returned, but when I re-executed the command above the problem was fixed again. So clearly this is just a matter of something not getting loaded correctly in Terminal, right?
I moved the command above in to ~/.bash_profile (which was previously empty other than prompt stylings), and the problem is totally fixed for me. I can close & reopen Terminal, and I'm off to the races.
BUT WHAT HAPPENED?! Why was that command in ~/.bash_login instead of ~/.bash_profile? I'd love to understand what's going on so that I get less n00bly & so that others can avoid the 2-hour Google searching adventure that I just had. :)
Thanks!
Environment:
- Mac OS X 10.7.4 (Lion)
- Terminal (built-in)
- Sublime Text 2