Ruby on rails 我尝试使用“gem install json”安装json,但似乎不起作用

Ruby on rails 我尝试使用“gem install json”安装json,但似乎不起作用,ruby-on-rails,ruby,json,rubygems,chef-infra,Ruby On Rails,Ruby,Json,Rubygems,Chef Infra,当我试图运行一个脚本来设置我的工作区时,我得到了这个错误 /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find json (<= 1.6.1, >= 1.4.4) amongst [bigdecimal-1.1.0, bundler-1.1.5, bunny-0.7.9, chef-10.14.4, erubis-2.7.0, highl

当我试图运行一个脚本来设置我的工作区时,我得到了这个错误

/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find json (<= 1.6.1, >= 1.4.4) amongst [bigdecimal-1.1.0, bundler-1.1.5, bunny-0.7.9, chef-10.14.4, erubis-2.7.0, highline-1.6.15, io-console-0.3, ipaddress-0.8.0, jruby-pageant-1.1.1, json-1.8.1, mime-types-1.19, minitest-2.5.1, mixlib-authentication-1.3.0, mixlib-cli-1.2.2, mixlib-config-1.1.2, mixlib-log-1.4.1, mixlib-shellout-1.1.0, moneta-0.6.0, net-ssh-2.2.2, net-ssh-gateway-1.1.0, net-ssh-multi-1.1, ohai-6.14.0, polyglot-0.3.3, rake-0.9.2.2, rdoc-3.9.4, rest-client-1.6.7, systemu-2.5.2, treetop-1.4.10, uuidtools-2.1.3, yajl-ruby-1.1.0] (Gem::LoadError)
    from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:777:in `block in activate_dependencies'
    from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:766:in `each'
    from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:766:in `activate_dependencies'
    from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:750:in `activate'
    from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems.rb:1232:in `gem'
    from /opt/chef/bin/chef-solo:22:in `<main>'
you have a different version of chef installed and we don't support uninstalling them with this script, we only support version 10.14.4
它吐出了这个

WARNING:  Error fetching data: Errno::ETIMEDOUT: Operation timed out - connect(2) (https://gem.vistacore.us:8443/gem/specs.4.8.gz)
WARNING:  Error fetching data: Errno::ETIMEDOUT: Operation timed out - connect(2) (https://nexus.vistacore.us:8443/gem/specs.4.8.gz)
Fetching: json-1.6.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed json-1.6.1
1 gem installed
Installing ri documentation for json-1.6.1...
Installing RDoc documentation for json-1.6.1...
但是当我尝试重新运行我的工作区脚本时,我再次遇到第一个错误。好像什么都没安装。发生什么事了


谢谢

首先,让我们列出您的所有ruby版本,因为您可能有多个版本

$ rvm list ruby
第二,也要检查你的gem版本,如果版本与你的程序不匹配,那就扔掉那些东西,把它想要的版本放进去,或者做一些修改

查看gem版本后

检查所有环境变量,如$GEM\u HOME等

有时,本机扩展会因为环境变量可能已关闭而丢失。在您修复了所有这些之后,您会很好,只需安装json gem

$ gem install json
无需指定版本,它将自动获取所需的版本

请记住,rubygem是基于自己的版本安装gems的,而您由rvm安装的rubygem版本是基于rvm安装的ruby版本的,所以这一切都要追溯到安装时您机器上安装的ruby和rubygems rvm的版本。如果rubygem和ruby版本是正确的,那么当您安装程序时,它将自动提取与您的程序兼容的json gem,正确添加您的env变量有助于构建本机扩展并帮助您的程序查看所有内容。我希望这有助于从实际错误中了解一些情况。

您安装了不同版本的chef,我们不支持使用此脚本卸载它们,我们只支持版本10.14.4


我会尝试卸载你的版本,然后使用chef 10.14.4安装。你的Gemfile中有json gem吗?我没有Gemfile目录,但我有一堆Gemfile,打开它们会发现其中一些有json 1.8.1,其他人似乎没有。你需要json吗?你能运行ruby-v和哪个ruby并将输出粘贴到这里吗?@sethvargo我不确定你所说的需要json是什么意思不需要在答案中不断更改你的名字;这没有关系。如果要更改您的姓名,请更新您的个人资料名称。
$ rvm use (foo)
$ gem --version
$ gem install json