Alex Antonov
Alex Antonov

Reputation: 15156

RVM must cd to directory to change gemset according to .ruby-version & .ruby-gemset

I found a strange behaviour with RVM, and don't know how to deal with it.

It seems RVM can't automatically change its gemset per .ruby-version & .ruby-gemset if I open a terminal exactly in the root of project. Please review what I mean

# open a terminal directly in terminal_ui directory, which contains .ruby-version & .ruby-gemset

ls -a # ... .ruby-version .ruby-gemset
rvm gemset list
gemsets for ruby-2.2.1 (found in /home/epic/.rvm/gems/ruby-2.2.1)
=> (default)
   fasteria
   global
   terminal
   terminal_ui

# but if I cd to the top and then back again, my gemset will be 

cd ../
cd terminal_ui
rvm gemset list
gemsets for ruby-2.2.1 (found in /home/epic/.rvm/gems/ruby-2.2.1)
   (default)
   fasteria
   global
   terminal
=> terminal_ui

Helpful information:

 cat .ruby-version # => 2.2.1
 cat .ruby-gemset # => terminal_ui
 rvm -v # => rvm 1.26.11

I've tried rvm get stable, but with no success.

Upvotes: 1

Views: 796

Answers (2)

hedgesky
hedgesky

Reputation: 3311

RVM uses several hooks to change ruby version and gemsets on user actions:

  • after_use
  • before_install
  • after_install
  • after_do (Triggered after any 'do' action)
  • after_cd (Triggered whenever a user uses the cd command)

When you open terminal just in project folder, you don't use command, so hook isn't called. But you can add following line in your .bashrc or .bash_profile file (after RVM-related lines):

cd .

It will cause RVM to use its hook and set proper gemset. More about hooks: docs.

Upvotes: 7

user3690603
user3690603

Reputation: 33

You can use .rvmrc for change automatically.

cd terminal_ui
touch .rvmrc
echo rvm use 2.1.1@terminal_ui >> .rvmrc
cd .

Upvotes: 0

Related Questions