简体   繁体   中英

How to use RVM and different versions of rails

Hi I am beginner to ruby on rails. I have following this on my machine

nilkash@nilkash:~$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]
nilkash@nilkash:~$ rails -v
Rails 3.2.3
nilkash@nilkash:~$ rvm -v

rvm 1.19.6 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

nilkash@nilkash:~$ rvm list

rvm rubies

=* ruby-1.9.3-p392 [ i686 ]

# => - current
# =* - current && default
#  * - default

nilkash@nilkash:~$ rvm gemset list

gemsets for ruby-1.9.3-p392 (found in /home/nilkash/.rvm/gems/ruby-1.9.3-p392)
   (default)
   global
   latest_rails_stable
=> rails3tutorial2ndEd 

I also install rails version 4.0.0. But I don't know how to use different versions of rails. when i create new project it shows rails version 3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. Need Help. Thank you.

I also install rails version 4.0.0. But I don't know how to use different versions of rails. when i create new project it shows rails version 3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. Need Help. Thank you.

this is because you're still using the current gemset rails3tutorial2ndEd

You need to create a different gemset:

rvm gemset create <new_gemset_name>

then use it:

rvm gemset use <new_gemset_name>

and finally install a new rails version:

gem install rails -v <version_number>

only after doing these things will you be able to make a new project with a different rails version.

If you want to only do a quick command in different rails version you can do:

 $ rails _4.0.1_ new MyRailsApp

That way you don't have some gems installed twice as you do when you use gem sets. Bundler should handle the rest so you should only need one gemset.

In your Gemfile, you will see the line gem 'rails', '3.2.3' or which version you are using. You can modify it and execute bundle again.

You can execute gem list --local on the console to check all versions of your gems installed.

In my opinion, you would better to use rvmrc to define different gemset in the different projects, it reduces chaos. see details: https://rvm.io/workflow/projects

你可以用rvm gemset create <gemset name>然后切换到它rvm use <ruby version>@<gemset name>并在这个gemset中安装另一个版本的rails

You can have a different ruby version for different gems. I am going to give an example way to manage for ruby 2.1.10 with rails 4.1 and ruby 2.4.1 with rails 5.1. This is a quote from rvm official website take a look.

RVM gives you compartmentalized independent ruby setups. This means that ruby, gems and irb are all separate and self-contained - from the system, and from each other.

You may even have separate named gemsets.

I am supposing you had already installed a different version of ruby. To list user rvm list . It will list installed ruby and currently which one be using. if you have not installed any no problem follow this official rvm documentation .

  • Install 2.1.10 with rails 4.1.0

    rvm use 2.1.10 gem install rails -v 4.1.0 rvm use 2.1.10@rails410 --create rvm 2.1.10

ready and good to go for ruby 2.1.10 with rails 4.1.0

  • Install 2.4.1 with rails 5.1.0

    rvm use 2.4.1 gem install rails -v 5.1.0 rvm use 2.4.1@rails510 --create rvm 2.4.1

ready and good to go ruby 2.4.1 with rails 5.1.0

You have set 2 gemsets above. Just use rvm 2.1.10 for ruby 2.1.10 and rails 4.1 and rvm 2.4.1 for ruby 2.4.1 and rails 5.1.0.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM