Error installing bcyrpt-ruby gem bundle

2019-05-20 07:23发布

问题:

I'm trying to install the Devises gem, running bundle install and then getting this error with bcrypt-ruby which I haven't had before. What can I do?

Installing bcrypt-ruby (3.0.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
creating Makefile

make
xcrun cc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common   -c bcrypt_ext.c
Error: No developer directory found at /Developer. Run /usr/bin/xcode-select to update the developer directory path.
make: *** [bcrypt_ext.o] Error 1


Gem files will remain installed in /Users/Fryed/.bundler/tmp/25124/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /Users/Fryed/.bundler/tmp/25124/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
An error occured while installing bcrypt-ruby (3.0.1), and Bundler cannot continue.
Make sure that `gem install bcrypt-ruby -v '3.0.1'` succeeds before bundling.

Okay, so I need to install bcrypt-ruby...

wpub-6-65:treebook Fryed$ sudo gem install bcrypt-ruby -v '3.0.1'
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing bcrypt-ruby:
    ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
creating Makefile

make
xcrun cc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common   -c bcrypt_ext.c
Error: No developer directory found at /Developer. Run /usr/bin/xcode-select to update the developer directory path.
make: *** [bcrypt_ext.o] Error 1


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out

回答1:

Either you haven't installed XCode or your developer directory is configured incorrectly.

If the first, try installing XCode.

If the second, try this (or some variation, depending on where your XCode directory is)

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer


回答2:

gem 'bcrypt-ruby', '~>3.0.1', :github => 'rking/bcrypt-ruby'

rking's fork of bcrypt-ruby comments out failing c compilation patch for 3.0.1. Bcrypt-ruby fixed this problem a year ago, but not for version 3.0.1, which seems to be the dependency your Rails app requires.

See the issue on github: https://github.com/bundler/bundler/issues/2410