22

I know how to use RVM, but now I have a weird problem, which I do not understand why.

Here is the simple story (I am using Ubuntu):

I have created a Rails project, the direcotry of this project is "bookstore/".

I go to project directory by cd bookstore , and type command rvm list like following:

bookstore/$ rvm list

rvm rubies

   ruby-1.9.2-p136 [ i386 ]
   ruby-1.8.7-p352 [ i386 ]
   ruby-1.8.7-p330 [ i386 ]
   ruby-1.8.6-p420 [ i386 ]
   ruby-1.9.2-p290 [ i386 ]

Since I did not see the => arrow sign which is supposed to indicate the current ruby version in use, so I specify the ruby version with the following RVM command:

bookstore/$ rvm use ruby-1.9.2-p290
Using /home/usr/.rvm/gems/ruby-1.9.2-p290

Now, if I rvm list I see my project is using ruby v1.9.2 :

bookstore/$ rvm list
rvm rubies

   ruby-1.9.2-p136 [ i386 ]
   ruby-1.8.7-p352 [ i386 ]
   ruby-1.8.7-p330 [ i386 ]
   ruby-1.8.6-p420 [ i386 ]
=> ruby-1.9.2-p290 [ i386 ]

Every thing works fine at this point!

But, if now I open a new terminal window on Ubuntu, and cd to the project directory, and run the command rvm list again, I got:

bookstore/$ rvm list

rvm rubies

    ruby-1.9.2-p136 [ i386 ]
    ruby-1.8.7-p352 [ i386 ]
    ruby-1.8.7-p330 [ i386 ]
    ruby-1.8.6-p420 [ i386 ]
    ruby-1.9.2-p290 [ i386 ]

Where is the => to indicate the ruby version I specified previously? Why it again needs me to specify the ruby version?

It happens always when I open a new terminal window. How to have my project "remember" the ruby version I have specified?

2 Answers 2

31

Dave is right, you should set a default. But also, look into defining an .rvmrc file on a per-project or per-machine basis. I use project-specific rvmrc files, so I can use different rubies and gemsets for each project, and changing into the directory automatically switches to that project's ruby/gemset.

For example, my rvmrc for company site project:

brett@bender:~/Sites/bearded/bearded(master)$ cat .rvmrc 
rvm 1.9.3@bearded

Edit: For explicitness' sake, to solve your problem using an rvmrc file, do the following (assuming you already installed the ruby version you want and created a gemset for this project's gems):

  1. Create a file in bookstore/ directory named .rvmrc (in your favorite editor)
  2. Add rvm ruby-1.9.2-p290 to the file and save it (you can use rvm ruby-1.9.2-p290@gemset_name if you have a gemset you want to default to)
  3. Change directory out of your bookstore directory, then change back into it.
  4. RVM should ask you if you want to trust this .rvmrc file (yes)
  5. RVM should have automatically switched your active ruby and gemset to the ones specified in your rvmrc file for that project.

Also note that if your RVM is older than version 1.8.0 you will need to turn on rvmrc file support (versions 1.8.0+ have it turned on by default). The link at the top of my question contains instructions if you're so inclined.

3
  • If it can be used to specify per-project ruby usage, should I create this file separately in my different projects folders?
    – Mellon
    Commented Nov 18, 2011 at 17:19
  • Yes, my project folder is Sites/bearded/bearded (that is the dir my app, db, config, etc folders live in for a rails project). The rvmrc file is at Sites/bearded/bearded/.rvmrc. Changing directory to the directory the rvmrc is in automatically switches to the right ruby version and gemset (listed in the rvmrc file). Pretty nice! Commented Nov 18, 2011 at 17:20
  • Can you make it clear in you answer with my case, so that other people who have the same confuse can directly check your answer? It would be nice if you can answer with per-project and per-machine separately.
    – Mellon
    Commented Nov 18, 2011 at 17:21
8

You need to set the default.

rvm --default 1.9.2-p290  # Or whichever.

A new shell is a new environment; it will not (normally) inherit from already-opened terminals

For per-project settings, use a .rvmrc file in the root of your project, for example:

rvm --create gemset use 1.9.2-p0@my_project

The --create will create the gemset if it does not already exist, handy if you or others work on the same project across machines.

4
  • Is it a project specific default setting or global default setting? How to have project specific setting and global default setting respectively?
    – Mellon
    Commented Nov 18, 2011 at 17:16
  • @Mellon Use a .rvmrc file in the project's root directory. Commented Nov 18, 2011 at 17:20
  • should I run the per-project command under my project folder?
    – Mellon
    Commented Nov 18, 2011 at 17:34
  • You don't run anything, you put the .rvmrc file in your project's root folder. Commented Nov 18, 2011 at 17:40

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