Installing bcrypt gem failed

1.8k views Asked by At
gem install bcrypt
Building native extensions.  This could take a while...
ERROR:  Error installing bcrypt:
    ERROR: Failed to build gem native extension.

    /Users/mohit/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb
creating Makefile

make  clean

make
compiling bcrypt_ext.c
make: /usr/local/opt/gcc46/bin/gcc-4.6: No such file or directory
make: *** [bcrypt_ext.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/mohit/.rvm/gems/ruby-1.9.3-p547/gems/bcrypt-3.1.9 for inspection.
Results logged to /Users/mohit/.rvm/gems/ruby-1.9.3-p547/extensions/x86_64-darwin-13/1.9.1/bcrypt-3.1.9/gem_make.out

Edit with additional info from the OP:

$ xcode-select --install 
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

$ brew doctor
Warning: You have uncommitted modifications to Homebrew 
If this a surprise to you, then you should stash these modifications. 
Stashing returns Homebrew to a pristine state but can be 
undone should you later need to do so for some reason. 
cd /usr/local/Library && git stash && git clean -d -f

$ brew info gcc 
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require': 
cannot load such file -- global (LoadError) from 
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:
in require' from /usr/local/Library/brew.rb:16:in `<main>'

$ gcc -v 
Configured with:
  --prefix=/Applications/Xcode.app/Contents/Developer/usr
  --with-gxx-include-dir=/usr/include/c++/4.2.1 
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) 
Target: x86_64-apple-darwin14.0.0 Thread model: posix

$ ls -ladg /usr/local/opt/gcc* 
No such file or directory 
3

There are 3 answers

5
joelparkerhenderson On BEST ANSWER

OSX help

  1. Try installing XCode, which tends to be a huge download:

    $ xcode-select --install
    
  2. If the result is anything like this message below, that's ok for now.

    command line tools are already installed, 
    use "Software Update" to install update
    
  3. Update OSX to ensure it's ok and current:

    Apple Menu -> About This Mac -> Software Update
    
  4. Verify you have a current system, 10.10 as of this writing:

    $ sw_vers
    ProductName: Mac OS X
    ProductVersion: 10.10
    BuildVersion: 14A389
    

Brew help

  1. If you use the homebrew package manager, what version? (Please post output)

    $ brew --version
    
  2. Verify brew is healthy:

    $ brew doctor
    
  3. If the doctor finds any errors, fix these. For example, doctor may say to do this, so do it:

    cd /usr/local/Library && git stash && git clean -d -f – 
    
  4. When doctor says everything is fine, then bring brew current:

    $ brew update
    $ brew upgrade
    
  5. Is homebrew adding GCC? (Please post output)

    $ brew info gcc 
    

GCC help

  1. Is GCC available?

    $ command -v gcc
    /usr/bin/gcc
    
  2. See if your CC compiler variable is blank or set. (Please post the output)

    $ echo $CC
    
  3. What GCC version are you running? (Please post the output)

    $ gcc -v
    ...
    Apple LLVM version 6.0 (clang-600.0.34.4) (based on LLVM 3.5svn)
    ...
    
  4. Do you have any GCC installed where Ruby is looking? (Please post the output)

    $ ls -ladg /usr/local/opt/gcc*
    lrwxr-xr-x 1 admin 21 Dec 18 16:41 /usr/local/opt/gcc -> ../Cellar/gcc/4.9.2_1
    

Root gem help

  1. Does the gem install if you're root?

    $ sudo su -
    $ gem install bcrypt
    
0
stujo On

Stuck working on an old project I was able to get the gem installed by using the following steps (check you own paths - don't just copy paste):

1) Install the specific version of gcc required (check the version) :

brew install gcc46

2) Symlink the installed gcc directory :

ln -s /usr/local/Cellar/gcc\@4.6/4.6.4_2 /usr/local/Cellar/gcc46/4.6.4

3) Install the gem reporting the error (check your gem name)

gem install bcrypt-ruby -v '3.0.1'
0
Shahin On

The root problem here is that ruby itself comes with bcrypt version 3.1.5 which is having bugs with the newer updates. However when you install or uninstall the bcrypt you are leving behind bcrypt-ruby which it always asks for first and hence all what you are doing won't go through so what to do ? 1- uninstall bcrypt and bcrypt-ruby by running these two commands:

$ gem uninstall bcrypt

and

$ gem uninstall bcrypt-ruby

2- Install it again with

gem install bcrypt --platform=ruby

In your Gemfile write gem 'bcrypt','~>3.1.11'

NOW as i write these lines the latest version is 3.1.11 but whatever version is updated just add it from their gem page. Run bundle install and it should work just fine.

I hope you fully understand the solution and the mechanism of it hence you would know that bundle install might cause the same issue so you have to repeat this process and it'll work again.