如何将多个 Rails 版本与 rbenv 一起使用?
是否可以通过 rbenv 使用多个版本的 Rails(例如 2.3 和 3.1)?使用 rvm 中的 gemsets 很容易,但我想知道既然我已经切换到 rbenv,最好的方法是什么(另外,我正在寻找一种不使用 rbenv-gemset 的方法)。
Is it possible to use multiple versions of rails using rbenv (e.g. 2.3 and 3.1)? This was easy with gemsets in rvm, but I'm wondering what the best way is to do it now that I've switched to rbenv (also, I'm looking for a way to do it without rbenv-gemset).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定你是否得到了答案,但我想我会提供我所做的,而且它似乎有效。
因此,一旦安装了 rbenv,并使用它来安装特定的 ruby 版本,您就可以为该 ruby 安装多个版本的 Rails。
步骤 1. 根据 ruby 版本安装您想要的任何版本的 Rails
通过在命令行中使用“RBENV_VERSION=1.9.2-p290”前缀,您可以指定哪个 ruby rbenv 应该是关心。
然后使用“rbenv exec”命令,就可以安装rails了。只需使用示例中的版本标志来指定您想要的版本。不确定是否可以一次性安装多个版本,但我只是根据需要多次运行此命令来安装我想要的每个版本。
注意:这一切都将在您的 rbenv 目录中进行管理,因此它是完全安全且可控的。
第 2 步:通过指定所需的 Rails 版本来构建新的 Rails 项目。
< strong>第3步。不要忘记进入该项目并设置本地rbenv ruby版本。
现在,如果您想删除该项目,只需像平常一样删除它即可。
如果您想从 rbenv gems 删除/管理 Rails 版本,您可以使用常规 gem 命令,只需在命令行中添加前缀:
当然,您可以删除完整的 ruby 版本及其所有在 rbenv 中管理的垫片等很容易。我喜欢一切都是那么自给自足。
希望这有帮助。
作为参考,这是至少其中一些内容的相当好的演练:
http://ascarter.net/2011/09/25/modern-ruby-development.html
not sure if you got an answer to this, but I thought I'd offer what I did and it seemed to work.
So once you get rbenv installed, and you use it to install a specific ruby version, you can install multiple versions of rails to for that ruby.
STEP 1. Install whatever version(s) of rails you want per ruby version
By using the "RBENV_VERSION=1.9.2-p290" prefix in your command line, you're specifying which ruby rbenv should be concerned with.
Then following that with the "rbenv exec" command, you can install rails. Just use the version flag as in the example to specify which version you want. Not sure if you can install multiple versions in one shot, but I just run this command as many times as needed to install each version I want.
Note: This will all be managed within your rbenv directory, so it's perfectly safe and contained.
STEP 2. Build a new rails project by specifying the rails version you want.
STEP 3. Don't forget to go into that project and set the local rbenv ruby version.
Now if you want to delete this project, just delete it as normal.
If you want to delete / manage a rails version from rbenv gems, you can use regular gem commands, just prefix your command line with:
And of course, you can delete a complete ruby version and all its shims, etc that are managed within rbenv pretty easily. I like how self contained everything is.
Hope this helps.
For reference, this is a pretty good walk through of at least some of this stuff:
http://ascarter.net/2011/09/25/modern-ruby-development.html
有一个名为 rbenv-gemset 的 rbenv 插件,其行为应类似于
rvm gemset< /code>-command 但由于 rbenv 从来没有打算以这种方式工作,所以我还没有尝试过。
我通常使用 Bundler 管理 Rails 版本,正如 Nathan 在其他答案之一的评论中建议的那样。我使用所需的 Rails 版本创建一个 Gemfile,运行
bundle install
,创建 Rails 应用程序,让它替换 Gemfile 并让 Bundler 接管:如果您想了解更多详细信息,我写了 我的博客上有一篇关于它的文章。
希望有帮助!
There is a rbenv plugin called rbenv-gemset which should behave similar to the
rvm gemset
-command but since rbenv was never intended to work this way, I haven't tried it.I usually manage Rails versions with Bundler as Nathan suggested in the comments of one of the other answers. I create a Gemfile with my desired Rails version, run
bundle install
, create the Rails application, let it replace the Gemfile and let Bundler take over:If you want more detail, I wrote an article on my blog about it.
Hope it helps!
如果您使用 rbenv 设置了 ruby,则以下内容将起作用。
安装最新版本的 Rails(
7.x
截至 2022 年 10 月)要使用最新的 Rails 版本创建一个 Rails 项目,
这将创建一个具有最新版本的 Rails 应用程序,以验证我们是否可以看到
Gemspec
文件中的 Rails 版本(或)在安装过程中查看日志,安装 Rails,
6.xxx
版本假设我们将安装 Rails
6.0.4.8
,然后发出以下命令现在,要创建一个
6.0.4.8
版本(之前已安装)的 Rails 项目,请指定Rails 版本以及 Rails 命令。这将创建一个
6.x
版本的 Rails 应用程序,以验证我们可以在Gemspec
文件中看到 Rails 版本(或者)在安装过程中查看日志,< a href="https://i.sstatic.net/Ydo7A.png" rel="nofollow noreferrer">
其他说明
项目。
rbenv rehash
为所有已知的 Ruby 可执行文件安装 shimsrbenv
ruby
环境变量。
Gemspec
文件。If you have setup ruby using
rbenv
the following will work.Installing rails, the latest version (
7.x
as of Oct 2022)To create a rails project with the latest rails version,
This will create a rails application with the latest version, to verify we can see the rails version in the
Gemspec
file (or) see the logs during the installation,Installing rails,
6.x.x.x
versionAssuming we are going to install rails
6.0.4.8
, then issue the following commandsNow, to create a rails project with
6.0.4.8
version (which is installed previously), specify the rails version along with the rails command.This will create a rails application with the
6.x
version, to verify we can see the rails version in theGemspec
file (or) see the logs during the installation,Other notes
projects.
rbenv rehash
Installs shims for all Ruby executables known torbenv
ruby
environment variables.
Gemspec
file by yourself.