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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.