简体   繁体   English

如何使用RVM和不同版本的rails

[英]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. 我还安装了rails 4.0.0版。 But I don't know how to use different versions of rails. 但我不知道如何使用不同版本的rails。 when i create new project it shows rails version 3.x. 当我创建新项目时,它显示rails版本3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. 我想将其升级到版本4.如何检查所有已安装的rails的列表以及如何使用最新的rails。 Need Help. 需要帮忙。 Thank you. 谢谢。

I also install rails version 4.0.0. 我还安装了rails 4.0.0版。 But I don't know how to use different versions of rails. 但我不知道如何使用不同版本的rails。 when i create new project it shows rails version 3.x. 当我创建新项目时,它显示rails版本3.x. I want to upgrade it to version 4. How to check list of all installed rails and how to use latest one. 我想将其升级到版本4.如何检查所有已安装的rails的列表以及如何使用最新的rails。 Need Help. 需要帮忙。 Thank you. 谢谢。

this is because you're still using the current gemset rails3tutorial2ndEd 这是因为你仍在使用当前的gemset rails3tutorial2ndEd

You need to create a different gemset: 您需要创建不同的gemset:

rvm gemset create <new_gemset_name>

then use it: 然后使用它:

rvm gemset use <new_gemset_name>

and finally install a new rails version: 最后安装一个新的rails版本:

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. 只有在完成这些操作之后,您才能使用不同的rails版本创建一个新项目。

If you want to only do a quick command in different rails version you can do: 如果您只想在不同的rails版本中执行快速命令,您可以执行以下操作:

 $ rails _4.0.1_ new MyRailsApp

That way you don't have some gems installed twice as you do when you use gem sets. 这样你就不会像使用gem套件那样安装两次宝石了。 Bundler should handle the rest so you should only need one gemset. Bundler应该处理其余部分,因此您只需要一个gemset。

In your Gemfile, you will see the line gem 'rails', '3.2.3' or which version you are using. 在Gemfile中,您将看到行gem 'rails', '3.2.3'或您正在使用的版本。 You can modify it and execute bundle again. 您可以修改它并再次执行bundle。

You can execute gem list --local on the console to check all versions of your gems installed. 您可以在控制台上执行gem list --local以检查所安装的gem的所有版本。

In my opinion, you would better to use rvmrc to define different gemset in the different projects, it reduces chaos. 在我看来,你最好使用rvmrc在不同的项目中定义不同的gemset,它可以减少混乱。 see details: https://rvm.io/workflow/projects 详情请见: 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. 您可以为不同的宝石使用不同的ruby版本。 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. 我将给出一个示例方法来管理带有rails 4.1的ruby 2.1.10和带有rails 5.1的ruby 2.4.1。 This is a quote from rvm official website take a look. 这是来自rvm官方网站的报价看看。

RVM gives you compartmentalized independent ruby setups. RVM为您提供分区的独立ruby设置。 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. 您甚至可能拥有单独的命名gemsets。

I am supposing you had already installed a different version of ruby. 我想你已经安装了不同版本的ruby。 To list user rvm list . 列出用户rvm list It will list installed ruby and currently which one be using. 它将列出已安装的ruby以及当前正在使用的ruby。 if you have not installed any no problem follow this official rvm documentation . 如果您没有安装任何问题,请按照此官方rvm 文档进行操作

  • Install 2.1.10 with rails 4.1.0 使用rails 4.1.0安装2.1.10

    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 准备好并且很好用于rails 4.1.0的ruby 2.1.10

  • Install 2.4.1 with rails 5.1.0 使用rails 5.1.0安装2.4.1

    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 准备好并且很好去ruby 2.4.1 with rails 5.1.0

You have set 2 gemsets above. 你已经在上面设置了2个宝石。 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. 只需use rvm 2.1.10 for ruby​​ 2.1.10和rails 4.1和rvm 2.4.1 for ruby​​ 2.4.1和rails 5.1.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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