Ryoma
Ryoma

Reputation: 31

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.

Upvotes: 0

Views: 1201

Answers (2)

Tommasina Miller
Tommasina Miller

Reputation: 36

I second @Danilo Cabello's recommendation to start fresh if you can. I just have a few other trouble-shooting ideas:

The fact that your bundle is installing gems in /vendor/bundle means that at some point, you must have specified the path with bundle install --path vendor/bundle as @mogbee alludes to. That path flag will load files associated with your gems into vendor/bundle instead of your system gem location. You might have done that if you're trying to keep the project's gems separate from any other project, but if not, you will need to update your bundler's gem path.

To do this, first, check for any issues by running bundle doctor. If no issues are found, check your bundle configuration with bundle env. Make sure that your RubyGems Gem Home and Gem Path are routed through .rbenv, so they should match and look like /Users/***/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0. If they don't match, run the rbenv-doctor command below which should make sure your rbenv installation exported the path properly.

If the output of bundle env tells you that you're actually running an older version of bundler (older than 1.16.4), I would definitely update, and would recommend version 1.17.3 as @Danilo Cabello did.

Second, I would run this rbenv-doctor curl command to check the status of your rbenv install: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash (https://github.com/rbenv/rbenv-installer#rbenv-doctor).

Third, depending on the output of ls -l within your project folder, you may also want to recursively change owner/group for your ~/.rbenv folder to make sure everything is owned by you and not root (https://superuser.com/questions/260925/how-can-i-make-chown-work-recursively/260939#260939)

Upvotes: 0

Danilo Cabello
Danilo Cabello

Reputation: 2963

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.

Upvotes: 0

Related Questions