88

I get the following error when attempting to run 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. 

It may be important to note that this deployment was working, than I upgraded to Ruby 2.1.0 to remove an encoding error. I upgraded locally which worked fine. I ran rvm install 2.1.0 and rvm use 2.1.0 then changed my .ruby-version file to reflect this Ruby upgrade.

The bundle install command works locally, but produces the same above error when I ssh onto the destination server and run this command.

If I run gem list I can see this in the list of gems.

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

If I try the recommended solution gem install json -v '1.8.1' Locally and on the destination server I get the following output:

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 

So it appears the gem is installed, right? Why is this happening? How can I solve this? Any help would be greatly appreciated.

6
  • What bundle show json gives you? Commented Jan 13, 2014 at 15:36
  • Add gem json, '1.8.1' to Gemfile Commented Jan 13, 2014 at 15:37
  • I have gem json, '1.8.1' in my gemfile already unfortunately Commented Jan 13, 2014 at 15:38
  • bundle show json give /Users/ME/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/json-1.8.1 Commented Jan 13, 2014 at 15:38
  • 6
    I needed sudo apt-get install ruby-dev on my Ubuntu. Commented Mar 1, 2016 at 16:43

19 Answers 19

76
$ bundle update json $ bundle install 
Sign up to request clarification or add additional context in comments.

5 Comments

This did it for me on Ruby 2.4.0!
Works for rbenv ruby 2.4.1 too (debian / ubuntu)
This worked for me as well. Ruby 2.4.0 High Sierra. Thank you!
Worked for me too under Ruby version 2.4.2p198. Thanks.
I upvoted this answer because it worked for me while the accepted answer did not. Like @Robert_T_Taylor, I ran this on macOS High Sierra.
68

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'

6 Comments

Had the same issue even after updating bundler, doing a gem install json -v '1.8.1' after updating fixed the error message for me.
gem install json -v '1.8.1' followed by bundle package did the trick for me
Isn't bundler supposed to install these gems for you? I don't understand why you have to install the gems manually. bundler.io/rationale.html I'm using Bundler version 1.7.11
This did not worked for me, sudo apt-get install libgmp3-dev worked , found solution github.com/flori/json/issues/253
I'm using bundler version 1.14.6 and also getting this error
|
49

Run this command then everything will be ok

sudo apt-get install libgmp-dev 

Comments

41

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!

Comments

35

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.

2 Comments

+1 Really helpful and got me unstuck. After bundle update, the install worked great. Thank you for the clean solution.
bundle update will update all your gems. gem update bundler will update bundler.
20

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 

2 Comments

This worked fantastically for me on OSX, Ubuntu across multiple bad versions of the json gem. In one case I had to delete the lock file and rebuild from scratch: git rm Gemfile.lock bundle install
Worked fine, first of all I delete the Gemfile.lock and then just run bundle install and that's it.
12

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.

Comments

9

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.

3 Comments

Worked when upgrading from ruby 2.0.0 to 2.2.4.
No need to delete everything. "bundle update json" sufficed.
Using gem 'json', '1.8.6' worked for me. You might want to try that.
7

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.

2 Comments

Get the following error with your solution: "Version '2.1.0' is ambiguous. Cannot select Ruby implementation/version, please be more specific. Cannot reinstall unknown package ''"
You might not have ruby 2.1.0, or more than one version installed through rvm. Run rvm list, and you'll see what is your current version. Use the full string (e.g. ruby-2.0.0-p451) instead of the 2.1.0 mentioned above.
7

bundle update json. Helped to get through.

1 Comment

Successfully installed json 1.8.6 (was 1.8.3)
5

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

Comments

3

For OS X make sure you have coreutils

$ brew install coreutils $ bundle 

1 Comment

Although I got a warning "Warning: coreutils 8.32 is already installed and up-to-date", this did the trick.
2

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.

1 Comment

yup, it's simple to solve a problem with json bundle. Thank you
2

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

xcode-select --install 

Hope it helps.

Comments

2

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

Comments

1

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

1 Comment

Just running a bundle update solved this issue for me... in other words using a newer JSON gem build.
0

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

Comments

0

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

Comments

0

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'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.