Ruby-on-rails 如何在 RVM gemset 中安装 Rails 4.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15231798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:33:28  来源:igfitidea点击:

How do you install Rails 4.0 in an RVM gemset?

ruby-on-railsrvm

提问by user1096509

I am trying to install Rails into a new rvm gemset. I tried the following:

我正在尝试将 Rails 安装到新的 rvm gemset 中。我尝试了以下方法:

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

Next I did:

接下来我做了:

rvm [email protected]

rvm gemset list:

rvm 宝石列表:

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

导轨 -v

Rails is not currently installed on this system. To get the latest version, simply type:

$ sudo gem install rails

此系统上当前未安装 Rails。要获取最新版本,只需键入:

$ sudo gem install rails

Do the rvm commands I listed notinstall rails 4.0?

我列出的 rvm 命令是否没有安装 rails 4.0?

回答by Gary S. Weaver

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.

基本上是在创建一个目录结构来保存 gems。你可以很容易地将它称为“rails-4.0”以外的东西,比如“foo”,这将是相同的行为。

This command:

这个命令:

rvm [email protected]

Switches to Ruby 2.0.0 and tells it to use the new gemset named rails-4.0. Again, that could be "foo" or whatever you called it.

切换到 Ruby 2.0.0 并告诉它使用名为 rails-4.0 的新 gemset。同样,这可能是“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, e.g. 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. 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. But, rvm has you install things as the current user, therefore you don't need to sudo.

不要 sudo,因为你不应该用 rvm sudo,即使它告诉你。使用“系统 ruby​​”(ruby 不是由 rvm 安装),它可能以 root 身份安装,因此您需要超级用户 (su) 访问权限(超级用户 do 或“sudo”)来执行此操作。但是,rvm 让您以当前用户身份安装东西,因此您不需要 sudo。

回答by Barrett Clark

In addition to the usage tips above, if you don't specify the gem version you won't get the beta or pre version, so to get rails 4, you need:

除了上面的使用技巧,如果你不指定 gem 版本,你不会得到 beta 或 pre 版本,所以要得到 rails 4,你需要:

gem install rails --version=4.0.0.rc1

回答by Christopher Castiglione

Maybe try InstallRails?

也许尝试InstallRails?

http://installrails.com/is a guide for installing rails that deals with these issues for various Operating Systems and setups. It might prove helpful for something like this.

http://installrails.com/是安装 rails 的指南,用于处理各种操作系统和设置的这些问题。它可能证明对这样的事情有帮助。

回答by Jignesh Gohel

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). And I prefer using gemsets so I ran following commands:

现在我已经从 Github 分叉了一个存储库,并想用 Rails 5(边缘版本)和 Ruby 2.2.3(撰写本文时的最新稳定版本)测试该存储库的代码。我更喜欢使用 gemset,所以我运行了以下命令:

  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