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?
Selecting a version of Ruby You'll need to install bundler 1.2. x or above to use the ruby keyword and bundler 1.13. x or above to use a Ruby version specifier. You can use the ruby keyword in your app's Gemfile to specify a specific version of Ruby.
Ruby Version Manager (RVM) is a utility that allows you to add your own personal version of Ruby to a user. It allows you to add, remove, or have multiple versions of Ruby and its libraries live in your user directory.
Try running rvm --default 1.9. 2 instead. That works for me. Did you accidentally put the line to load rvm in your bashrc instead of your bash_profile ?
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):
bookstore/
directory named .rvmrc
(in your favorite editor)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)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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With