Search code examples
rubyruby-on-rails-4rubygemsbundlebundle-install

Rails bundle install doesn't work 'cause json version error


I just wanted to convert from ImageMagick v7 to ImageMagick v6. while doing that, this error was happened.

bundle install doesn't work correctly.

It seems like json version is something wrong.

How do I fix this error?

Environment below

  1. ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin17]
  2. Rails -v (couldn't find gem) (becuase bundle install can't work)
  3. json list / json (default: 1.8.3) multi_json (1.13.1, 1.11.2, 1.11.0)
  4. Bundler version 1.16.4
  5. Mac Mojave 10.14

when I do bundle install on terminal, then I got this error

Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.......
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 0.9.5
Fetching json 1.8.6
Installing json 1.8.6 with native extensions
Errno::EPERM: Operation not permitted @ chmod_internal -
/Users/***/projects/***/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/tests/test_json.rb
An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6' --source 
'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
rails was resolved to 4.2.6, which depends on
actionmailer was resolved to 4.2.6, which depends on
  actionpack was resolved to 4.2.6, which depends on
    actionview was resolved to 4.2.6, which depends on
      rails-dom-testing was resolved to 1.0.9, which depends on
        rails-deprecated_sanitizer was resolved to 1.0.3, which depends on
          activesupport was resolved to 4.2.6, which depends on
            json

I tried to do like this because error statement says Make sure that
gem install json -v '1.8.6' --source 'https://rubygems.org/' succeeds before bundling

but result shows like this

ERROR:  While executing gem ... (Errno::EPERM)
Operation not permitted @ chmod_internal - /Users/***/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/json-1.8.6/tests/test_json.rb

I can't understand this error statement

Errno::EPERM: Operation not permitted @ chmod_internal -

Also, I goggled a lot, then I update commandlinetool follow this https://howchoo.com/g/m2u0mmuwzda/macos-mojave-fix-invalid-active-developer-path

then, I did this command again,

sudo gem install json -v '1.8.6' --source 'https://rubygems.org/'

then, it's completely succeded like this.

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

But, if I do bundle install, still doesn't work: they show same error.


Solution

  • My recommendation is if possible to start fresh. Maybe your rbenv was not installed correctly, try reinstalling it, I suggest using brew install rbenv https://github.com/rbenv/rbenv#homebrew-on-macos

    Make sure to add the eval "$(rbenv init -)" to your ~/.bash_profile then open a new terminal.

    Navigate to the project directory and install the Ruby version you need: rbenv install 2.3.1

    You can make sure you are using that version by issuing rbenv use 2.3.1 and ruby --version.

    Now install bundler for that Ruby version, I suggest 1.17.3 for now (the latest before 2.0.1) gem install bundler -v '1.17.3'.

    You should be ready to bundle install.

    The most common scenario I see for a message Installing ... with native extensions to result in errors is usually due to the lack of binaries, header files and C related code to build that native extension, in your case the issue is due to permissions, hence why I am suggesting some fresh installation.