如何在ruby 2上安装gems?

如何在ruby 2上安装gems?,ruby,gem,installation,Ruby,Gem,Installation,我刚刚在MacMountainLion上安装了ruby 2,如何安装gems?事实上,我已经安装了两个,但有点不对劲。也许新的装置可以解决这个问题 macbook:~m$ gem install rails ERROR: Loading command: install (LoadError) cannot load such file -- openssl ERROR: While executing gem ... (NoMethodError) undefined me

我刚刚在MacMountainLion上安装了ruby 2,如何安装gems?事实上,我已经安装了两个,但有点不对劲。也许新的装置可以解决这个问题

macbook:~m$ gem install rails
ERROR:  Loading command: install (LoadError)
    cannot load such file -- openssl
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass
macbook:~ m$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
macbook:~ m$ gem -v
2.0.3
macbook:~ m$ 

安装gem-like-rails需要很多依赖库,您必须手动下载并安装这些库

或者,您可以尝试使用安装所有依赖库。如果您是ROR开发的新手,我强烈建议您使用来管理不同版本的ruby

一旦您使用自制软件安装了所有必要的依赖库,那么安装gem就相当简单了,请在用您感兴趣的gem替换“gemname”后执行以下操作

gem install <<gemname>>
gem安装

我遇到了相同的问题,但修复方法如下:


显然,OSX Mountain Lion的OpenSSL版本比Ruby 2所能容忍的要旧。使用
/Configure darwin64-x86\u 64-cc--prefix=/usr/local--openssldir=/usr/local/OpenSSL下载并安装最新的OpenSSL;制作sudo make安装
。然后使用
/configure--with openssl dir=/usr/local/openssl构建Ruby;制作sudo make安装
。Ruby的configure抱怨说,
——with openssl dir
是一个未知的选项,但是构建显然使用了它,因为任何依赖于SSL的东西,包括gem安装,现在都可以工作了

@tatojo我无法查看您的输出,请检查您的评论。由于扩展构建失败,您似乎需要安装openssl开发库。