为什么 bundler 不安装 JSON gem?

在尝试运行 cap production deploy时出现以下错误。

DEBUG [dc362284]    Bundler::GemNotFound: Could not find json-1.8.1.gem for installation
DEBUG [dc362284]    An error occurred while installing json (1.8.1), and Bundler cannot continue.
DEBUG [dc362284]    Make sure that `gem install json -v '1.8.1'` succeeds before bundling.

值得注意的是,这个部署正在工作,而不是升级到 Ruby2.1.0来删除一个编码错误。我在本地升级了,效果很好。我运行了 rvm install 2.1.0rvm use 2.1.0,然后修改了我的 .ruby-version文件以反映这次 Ruby 升级。

bundle install命令在本地可以工作,但是当我在目标服务器上运行 ssh 并运行此命令时,会产生同样的错误。

如果我运行 gem list,我可以在 gems 列表中看到这一点。

...
jquery-rails (3.0.4)
json (1.8.1)
less (2.3.2)
...

如果我在本地和目标服务器上尝试推荐的解决方案 gem install json -v '1.8.1',我会得到以下输出:

Building native extensions.  This could take a while...
Successfully installed json-1.8.1
Parsing documentation for json-1.8.1
Done installing documentation for json after 0 seconds
1 gem installed

看来宝石已经安装好了,对吧?为什么会这样?我该怎么解决这个问题?如果你能帮忙,我将不胜感激。

123134 次浏览

So after a half day on this and almost immediately after posting my question I found the answer. Bundler 1.5.0 has a bug where it doesn't recognize default gems as referenced here

The solution was to update to bundler 1.5.1 using gem install bundler -v '= 1.5.1'

This appears to be a bug in Bundler not recognizing the default gems installed along with ruby 2.x. I still experienced the problem even with the latest version of bundler (1.5.3).

One solution is to simply delete json-1.8.1.gemspec from the default gemspec directory.

rm ~/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/specifications/default/json-1.8.1.gemspec

After doing this, bundler should have no problem locating the gem. Note that I am using chruby. If you're using some other ruby manager, you'll have to update your path accordingly.

I ran into this error while trying to get a project to run on my local dev box (OSX 10.6), using Sinatra and Postgresql (through activerecord), running on an rvm'd ruby 2.1. I found my answer here: https://github.com/wayneeseguin/rvm/issues/2511

My exact problem (after the first block of log entries):

I also get an error when trying to build native extensions for gems

The answer:

rvm reinstall 2.1.0 --disable-binary

The explanation:

OSX does not have a package manager so all libraries have to be installed manually by user, this makes it virtually impossible to link the binary dynamically, and as you can see there are problems with the (pseudo)statically linked binary.

For the sake of completeness, I had first forgotten to update rvm (rvm get head), which yielded some other errors, but still needed the --disable-binary flag once I had done so.

If the recommended answer didn't help because you are already using a newer version of bundler. Try the solution that worked for me.

Delete everything inside your vendor folder. Add a line to your gemfile

gem 'json', '1.8.0'

Then run - bundle update json.

It seems to be an issue with 1.8.1 so going back to 1.8.0 did the trick for me.

Run this command then everything will be ok

sudo apt-get install libgmp-dev

I found the solution here. There is a problem with json version 1.8.1 and ruby 2.2.3, so install json 1.8.3 version.

gem install json -v1.8.3

I was missing C headers solution was to download it for Xcode, this is the best way.

xcode-select --install

Hope it helps.

$ bundle update json
$ bundle install

I installed the latest version of json:

gem install json

Then deleted the line json(1.8.1) from the Gemfile.lock and did a

bundle install

And then the Gemfile.lock file uses json(1.8.3) without erros

For OS X make sure you have coreutils

$ brew install coreutils
$ bundle

Switch ruby version from 1.9 to 2.2 with rvm did the job for me

bundle update json. Helped to get through.

You should try

$ sudo gem install json -v '1.8.2'

in my case (Ubuntu 14.04) that didn't work directly and I had to do this:

$ sudo apt-get install ruby-dev

and then I could install the gem and continue. Had one more problem that was fixed by:

$ sudo apt-get install libsqlite3-dev

Hoping helps.

For me, some of the answers mentioned earlier were helpful from understanding point of view, but those didn't solve my problem.

So this is what I did to solve issue.

  • Modified gemfile.lock to update json (2.0.2) (Earlier, it was 1.8.3)
  • Check the Bundler version installed (Bundler -v command). I had version 1.12.5 installed
  • Install bundler version 1.11.2 (using gem install bundler -v '1.11.2')
  • Then run bundle install

Bundle was failing to install json -v '1.8.1' and deleting my Gemfile.lock and running bundle again solved this issue for me.

if you are in MacOS Sierra and your ruby version is 2.4.0.The ruby version is not compatible with json 1.8.3.

You can try add this line in your Gemfile:

gem 'json', github: 'flori/json', branch: 'v1.8'

This works for me!

To solve this problem, simply run:

bundle update

It will update the version of your bundler. Then run:

bundle install

Your problem will get solve. Solution is well explained here.

For macOS Sierra:

I ran into this error When i used bundler(v1.15.3) in Rails(v4.2) project. The solution for me is gem uninstall bundler -v '1.15.3' and gem install bundler -v '1.14.6'.

When I tried to install the json gem using gem install json separate from just using bundle install I got ERROR: Failed to build gem native extension., looking that up I found using

    apt-get install ruby-dev

did the trick