为什么 gem 安装在与我运行的 Ruby 版本不同的目录中? [英] Why are gems installed in a directory with a different Ruby version than I’m running?

查看:23
本文介绍了为什么 gem 安装在与我运行的 Ruby 版本不同的目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我安装 gem 时,它会安装在名为 1.9.1 的目录中,尽管它不是我安装的 Ruby 版本:

When I install a gem, it gets installed in a directory named 1.9.1, despite that not being the version of Ruby I have installed:

$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

$ gem which rails
.../ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails.rb

为什么会这样?我没有安装其他 Ruby 版本(当然也没有安装 v1.9.1).

Why does this happen? I have no other Ruby versions installed (and certainly not v1.9.1).

推荐答案

请注意,以下内容也适用于撰写本文时所有更高版本的 Ruby,而不仅仅是 1.9.2.

Note that the following is also for all later Ruby versions as of this writing, not just 1.9.2.

根据 1.9.2 发布公告:

标准库安装在/usr/local/lib/ruby/1.9.1

此版本是库兼容版本".Ruby 1.9.2 几乎与 1.9.1 兼容,因此该库安装在 1.9.1 目录中.

This version is a "library compatible version." Ruby 1.9.2 is almost 1.9.1 compatible, so the library is installed in the 1.9.1 directory.

尽管它安装在不同编号的目录中,但它使用的是 1.9.2.RubyGems 可以通过 gem env 显示它正在使用的所有目录.

Even though it is installed in a differently-numbered directory, it is using 1.9.2. RubyGems can show all the directories it’s using via gem env.

这确保了一组已安装的 gems 仅被它们可以实际运行的版本使用(尤其是由于编译的 C 扩展),并且当升级到更新但库兼容"的版本时,一个不会不必重新安装所有 gem.

This ensures that a set of installed gems is only used by versions that they can actually run with (especially due to compiled C extensions), and that when upgrading to a newer, but "library compatible", version, one doesn’t have to reinstall all gems.

这篇关于为什么 gem 安装在与我运行的 Ruby 版本不同的目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆