简体   繁体   English

如何在RVM gemset中安装Rails 4.0?

[英]How do you install Rails 4.0 in an RVM gemset?

I am trying to install Rails into a new rvm gemset. 我正在尝试将Rails安装到新的rvm gemset中。 I tried the following: 我尝试了以下方法:

rvm gemset create rails-4.0
output: gemset created rails-4.0

Next I did: 接下来我做了:

rvm 2.0.0@rails-4.0

rvm gemset list: rvm gemset列表:

gemsets for ruby-2.0.0-p0 (found in /Users/me/.rvm/gems/ruby-2.0.0-p0)
   (default)
   global
=> rails-4.0

rails -v rails -v

Rails is not currently installed on this system. 当前未在此系统上安装Rails。 To get the latest version, simply type: 要获取最新版本,只需键入:

 $ sudo gem install rails 

Do the rvm commands I listed not install rails 4.0? 我列出的rvm命令是不是安装了rails 4.0?

This command: 这个命令:

rvm gemset create rails-4.0

is creating basically a directory structure to hold the gems. 正在创建一个基本的目录结构来保存宝石。 You could have just as easily called it something other than "rails-4.0" like "foo" and it would be the same behavior. 你可以像“foo”那样轻松地称它为“rails-4.0”之外的东西,它会是同样的行为。

This command: 这个命令:

rvm 2.0.0@rails-4.0

Switches to Ruby 2.0.0 and tells it to use the new gemset named rails-4.0. 切换到Ruby 2.0.0并告诉它使用名为rails-4.0的新gemset。 Again, that could be "foo" or whatever you called it. 再一次,这可能是“foo”或者你称之为的任何东西。

Now, to get Rails 4.0.x, you'd do: 现在,要获得Rails 4.0.x,您需要:

gem install rails --version=4.0

As Barrett pointed out earlier, to get a pre/beta/rc release, you can specify the whole version string, eg gem install rails --version=4.0.0.rc2 . 正如Barrett先前指出的,要获得pre / beta / rc版本,您可以指定整个版本字符串,例如gem install rails --version=4.0.0.rc2

Don't sudo, because you shouldn't sudo with rvm, even though it tells you to. 不要sudo,因为你不应该用rvm sudo,即使它告诉你。 With the "system ruby" (ruby not installed by rvm), it may be installed as root, so you need superuser (su) access (superuser do or "sudo") to do that. 使用“系统ruby”(ruby不是由rvm安装),它可能以root用户身份安装,因此您需要超级用户(su)访问权限(超级用户或“sudo”)来执行此操作。 But, rvm has you install things as the current user, therefore you don't need to sudo. 但是,rvm让你以当前用户身份安装东西,因此你不需要sudo。

除了上面的使用技巧之外,如果你没有指定gem版本,你就不会获得测试版或预版本,所以要获得rails 4,你需要:

gem install rails --version=4.0.0.rc1

Maybe try InstallRails? 也许尝试InstallRails?

http://installrails.com/ is a guide for installing rails that deals with these issues for various Operating Systems and setups. http://installrails.com/是安装rails的指南,用于处理各种操作系统和设置的这些问题。 It might prove helpful for something like this. 它可能会对此类事情有所帮助。

Other answers shows instructions for creating the gemset using default ruby version. 其他答案显示了使用默认ruby版本创建gemset的说明。

For creating a gemset and use it with different ruby version please follow the instructions below: 要创建gemset并使用不同的ruby版本,请按照以下说明操作:

Let's say on my machine I have following ruby versions installed and 2.2.0 is the default. 假设我的机器上安装了以下ruby版本,默认情况下为2.2.0。

 =*ruby-2.2.0 [ x86_64 ]
   ruby-2.2.1 [ x86_64 ]
   ruby-2.2.3 [ x86_64 ]

Now I have forked a repository from Github and want to test out the repo's code with Rails 5 (edge version) and Ruby 2.2.3 (the latest stable version at the time of this writing). 现在我从Github派了一个存储库,想用Rails 5(边缘版本)和Ruby 2.2.3(编写本文时的最新稳定版本)测试repo的代码。 And I prefer using gemsets so I ran following commands: 我更喜欢使用gemsets,所以我运行了以下命令:

  rvm use 2.2.3@forked-repo --create

That's actually a shortcut for 这实际上是一个捷径

  rvm 2.2.3
  rvm gemset create forked-repo

Next I would run following command to install bundler: 接下来我将运行以下命令来安装bundler:

  forked_repo_root$ gem install bundler     
  forked_repo_root$ bundle

That should install the gems used in your forked-repo in the gemset created above. 这应该在你上面创建的gemset中安装forked-repo中使用的gem。

Reference: https://rvm.io/gemsets/creating 参考: https//rvm.io/gemsets/creating

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

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