Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Just switched to lion a couple of days back, and juts noticed that when you quit Terminal while in a folder, when you open it, it should be back in that folder(along with your other tabs).

This is a good feature indeed, but the problem is, it doesn't "refresh" your paths. meaning even if you had a .rvmrc file in your app folder, it won't set the ruby and gemset again. you'll have to actually cd out and get back in again, which defeats the purpose of having an rvmrc.

Is this a known bug and are there an fixes/patches for it already?

EDIT Following Chris Page's advice, I added cd "$PWD" in the last line of my .bashrc (which is loaded by my .bash_profile)

This in turn "loads" the rvmrc as expected :

Last login: Tue Aug  9 11:29:09 on ttys003
Using /Users/eumir/.rvm/gems/ruby-1.9.2-p180 with gemset mygemset

eumir$ gem list
/Users/eumir/.rvm/rubies/ruby-1.9.2-p180/bin/gem:12:in `require': no such file to load -- rubygems (LoadError)
from /Users/eumir/.rvm/rubies/ruby-1.9.2-p180/bin/gem:12

eumir$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

As you can see, it did load the gemset(printed out by "Using /Users...") but trying to do gem list and showing the ruby version says that it still didn't load it. (the ruby version should be 1.9.2)

EDIT 2

I updated my rvm and now any of the fixes aren't working!

It prints out that it IS using the gemset in my rvm but when I do a gem env, i get this:

eumir$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.6
  - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
  - INSTALLATION DIRECTORY: /Users/eumir/.rvm/gems/ruby-1.8.7-p174@awetest
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/eumir/.rvm/gems/ruby-1.8.7-p174@awetest/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-11
  - GEM PATHS:
     - /Users/eumir/.rvm/gems/ruby-1.8.7-p174@mygemset
     - /Users/eumir/.rvm/gems/ruby-1.8.7-p174@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://rubygems.org/", "http://gemcutter.org"]
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gemcutter.org

doing cd ../ and then cd myfolder and then gem env results with this:

eumir$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.7.2
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0]
  - INSTALLATION DIRECTORY: /Users/eumir/.rvm/gems/ruby-1.8.7-p174@awetest
  - RUBY EXECUTABLE: /Users/eumir/.rvm/rubies/ruby-1.8.7-p174/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/eumir/.rvm/gems/ruby-1.8.7-p174@awetest/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-10
  - GEM PATHS:
     - /Users/eumir/.rvm/gems/ruby-1.8.7-p174@mygemset
     - /Users/eumir/.rvm/gems/ruby-1.8.7-p174@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://rubygems.org/", "http://gemcutter.org"]
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gemcutter.org

which is the correct environment. As you can see, the gemset was loaded correctly(along with the gems) but it is still using the system ruby instead of the rvmrc ruby.

share|improve this question

migrated from stackoverflow.com Aug 6 '11 at 12:29

This question came from our site for professional and enthusiast programmers.

    
You can just source path/to/.rvmrc... –  Matt Ball Aug 5 '11 at 3:40
    
where? do i have to do this every time? i accidentally mistyped a cd command and apparently, cd ./ will refresh the directory and reload your rvmrc. im looking for a solution though that wont need me to type anything else –  corroded Aug 5 '11 at 3:42
    
Have you tried adding cd ./ to your .bash_profile? –  Warren Pena Aug 8 '11 at 23:37
    
Are you using a version of RVM older than 1.6.10? That release included cb649ba (Always load the .rvmrc if in an interactive shell (open new tab in same dir)., 2011-05-14)]. That change, which (more, or less) exists in the latest versions, should let it load .rvmrc files even for the initial, inherited current working directory (i.e. Terminal did a chdir(2) before starting the shell instead of having the shell do a cd itself (where RVM could notice it)). –  Chris Johnsen Aug 9 '11 at 4:06
    
hmmm upon checking, yes i was using rvm 1.6.5. so i guess ill just have to upgrade and take away my fix? I'll try to do that in awhile and check. If you could also post this as an answer I can accept that once i confirm this. Thanks! –  corroded Aug 9 '11 at 4:13

4 Answers 4

up vote 1 down vote accepted

Try upgrading your installation of RVM if you are running something older than 1.6.10 (check your active version with rvm --version).

In some shell:

rvm get latest

Then, either restart your other, existing shells, or run rvm reload in them.

Note: Another problem the OP faced was PATH manipulation after RVM was loaded into the shell. This created the “right gemset selected, but wrong installation of ruby” effect that disappeared after “cd out, cd in” (since RVM would have reasserted its position in the PATH at that point). When a shell is started in a directory that contains an .rvmrc it is vital that RVM be the last thing to prepend elements to the PATH (at least any PATH elements that might contain a ruby (etc.) so that the Ruby installation selected in the .rvmrc will be effective).


RVM arranges to source .rvmrc files by “hooking” your shell’s cd command (a cd shell function in bash, an entry in chpwd_functions for zsh). Normally this lets it catch any “normal” cd command that you type it or run via a sourced script after loading RVM.

I do not have Lion to test with, but I suspect the way it works is that Terminal forks, calls chdir(2), then execs your shell to establish your new shell’s initial working directory. This means that the directory is already established by the time RVM is loaded in your shell initialization file.

The history seems a bit muddy, but RVM has had some support for sourcing the .rvmrc file in the shell’s initial working directory when it is first loaded. It looks like maybe it was intended to be screen-specific, but in RVM commit cb649ba (Always load the .rvmrc if in an interactive shell (open new tab in same dir)., 2011-05-14) relaxed the requirement so that it should source .rvmrc files for any interactive shell when RVM is first loaded. This commit was first present in the 1.6.10 release of RVM. The code has changed a bit since then, but it still works in (more or less) the same way in the latest versions.

share|improve this answer
    
actually i just checked and though it does load the gems, it doesn't load my commands like rails, spork and cucumber? it throws and error: /Users/eumir/.rvm/gems/ruby-1.9.2-p180@evolux/bin/spork:9:in `require': no such file to load -- rubygems (LoadError) from /Users/eumir/.rvm/gems/ruby-1.9.2-p180@evolux/bin/spork:9 –  corroded Aug 9 '11 at 6:03
    
but doing gem list and gem env shows it loaded the correct gemset..maybe the paths are mucked up? i had to cd out and cd back in to make it work again... –  corroded Aug 9 '11 at 6:04
    
okay i just checked, it loads the correct gemset but the wrong ruby. ruby -v gives me 1.8.7 when it SHOULD BE 1.9.2. do you know why this happens? –  corroded Aug 9 '11 at 6:08
    
I do not understand what you mean when you say “it doesn’t load my commands like rails, spork and cucumber”. Are you using your .rvmrc to run those commands? Exactly what lines are in your .rvmrc? (I usually just put rvm use ruby-1.9.2-head@mygemset in there.) –  Chris Johnsen Aug 9 '11 at 7:16
    
ah when i try "rails s" to start my server or "spork cuc", it says rubygems is not loaded. when I cd out of my directory and cd in "spork cuc" or "rails s" works –  corroded Aug 9 '11 at 7:36

Lion Terminal selects/restores the working directory by setting it with chdir() before the shell starts. If you want to automatically perform some sort of additional work related to the working directory, you should customize the shell with a startup script that performs some command with $PWD.

Assuming you're using bash (the default), what you apparently would want to do is add something like this in ~/.bashrc:

cd "$PWD"

I'm not familiar with rvmc, but I assume it must use the shell startup script to customize the "cd" command, so be sure to issue this command after that. Also, if you don't already have shell startup scripts, you'll usually want to create ~/.bash_profile and have it run ~/.bashrc if it exists (look around on StackExchange or use Google to find this common idiom).

share|improve this answer
    
I added the cd thing in my bashrc and it almost worked. I'll update the question so you can see what i mean –  corroded Aug 9 '11 at 3:31

I know its not a "fix", but you can exit the terminal with command+option+q it will quit without saving the path information.

Or you can use iTerm2 ( http://www.iterm2.com/ ), it have a few better things than default terminal .

share|improve this answer
    
that would still make me cd into the directory i need to. what i was thinking of was if lion opened it to the directory(or directories) i was in when i exited, it should automatically load the rvmrc –  corroded Aug 6 '11 at 2:19

Fix 1: Okay found the better solution. So I created a script named .loadrvmrc and which only contained "cd ./" (also chmod +x it)

I then loaded it in my .bash_profile, BUT take note that it should be loaded in order.

First, load your .bashrc:

source ~/.bashrc

then your path(which loads rvm:

export PATH=/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/Users/eumir/.rvm/bin:$PATH

and THEN the .loadrvmrc script:

source ~/.loadrvmrc

Voila! You can close your terminal and open it with all your tabs and all their respective .rvmrcs.

=========== Fix 2: (non-programmatic)

I have fixed it for now. Maybe it's a timing issue for rvm or bashrc, so I'm not sure. If someone can post a better fix/answer for this one please do so and I'll change the accepted answer for this question.

Anyway in the default Terminal, I just changed Terminal > Preferences > Settings and then checked Startup and added cd ./ as the startup script.

This is still ugly for me as starting the terminal will result with

Last login: Tue Aug  9 11:43:06 on ttys003
eumir$ cd ./
Using /Users/eumir/.rvm/gems/ruby-1.9.2-p180 with gemset mygemset
eumir$ 

which is kinda acceptable(until a better solution comes along).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.