9

I am trying to encorporate bcrypt-ruby, v. 3.0.1. I enter the gem in my gem file as follows:

gem 'bcrypt-ruby', '3.0.1'

And I then go to the terminal and run:

bundle install

I get the following response:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb 
creating Makefile

make
compiling bcrypt_ext.c
make: gcc-4.2: No such file or directory
make: *** [bcrypt_ext.o] Error 1


Gem files will remain installed in /Users/philip7899/.bundler/tmp/2186/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /Users/philip7899/.bundler/tmp/2186/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
An error occurred 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.

I am extremely new to both Ruby and Rails and have no idea how to fix this. I have seen other stackoverflow pages with similar questions but none have been able to help me. I recently upgraded to Mountain Lion and was told that could be an issue. I was told to use RVM to uninstall and then reinstall Ruby. I tried that and it did not work.

Please help. Thank you.

Philip7899
  • 4,599
  • 4
  • 55
  • 114
  • Can you please include the contents of `/Users/philip7899/.bundler/tmp/2186/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out`? – Tim Moore Sep 24 '13 at 07:03
  • Related: https://stackoverflow.com/questions/12650773/cant-install-bcrypt-ruby-for-new-rails-installation – Timo Huovinen Sep 09 '21 at 09:30

10 Answers10

26

In recent versions bcrypt-ruby seems to use the GMP library.

So, on Linux something like this should help (command for Ubuntu 14.04):

sudo aptitude install libgmp-dev
Envek
  • 4,426
  • 3
  • 34
  • 42
5

Try removing ,'3.0.1' or try like this gem "bcrypt", "~> 3.1.1"

Hope it helps.

If not, from console try running gem install bcrypt

Yaro
  • 570
  • 3
  • 20
  • Then I just can forward you [here](http://stackoverflow.com/questions/6119153/why-do-i-get-a-bcrypt-ruby-gem-install-error). – Yaro Sep 23 '13 at 20:55
  • The combination of your answer plus the link you sent me (which I had tried before) worked! Thank you! – Philip7899 Sep 23 '13 at 20:58
  • 1
    Looks like `bcrypt-ruby` has been renamed to `bcrypt`: https://github.com/codahale/bcrypt-ruby#how-to-install-bcrypt. So: `gem "bcrypt", "~> 3.1.1"`. – Adobe Jan 21 '16 at 12:20
  • @Adobe Thanks! Updated the answer – Yaro Jan 21 '16 at 15:28
4

Actually a simple:

gem install bundler
gem install bcrypt-ruby

and then:

bundle update bcrypt-ruby
or bundle update bcrypt

Would've done the trick.

It's much the same way that you would upgrade rails. If you wanted to make sure you could also specify the latest bcrypt-ruby in your Gemfile. I just did this ten minutes ago so I know it works as of the date of this post... I was using ruby 1.9.3 p484

discipleartem
  • 181
  • 12
mystic cola
  • 1,465
  • 1
  • 21
  • 39
2

I think that's a problem of xcode upgrade.

My solution:

brew install apple-gcc42
sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2

and it works

big-circle
  • 547
  • 2
  • 11
2

I managed to fix my issue with installing Bcrypt 3.1.11 gem which was failing with:

linking shared-object bcrypt_ext.bundle
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bcrypt_ext.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/adrian/.rvm/gems/ruby-2.1.6/gems/bcrypt-3.1.11 for inspection.
Results logged to /Users/adrian/.rvm/gems/ruby-2.1.6/extensions/x86_64-darwin-14/2.1.0/bcrypt-3.1.11/gem_make.out

The problem was the libgmp wasn't found. First, install it via brew:

brew install gmp

Next, ensure that gcc will find the libraries by setting the LIBRARY_PATH environment variable:

export LIBRARY_PATH=/usr/local/lib

And install:

gem install bcrypt
AdrianCooney
  • 727
  • 5
  • 13
2

You will need to run the following command on Ubuntu/Debian:

sudo apt install ruby-dev
Silviu
  • 31
  • 3
0
  1. add the required gem to Gemfile
  2. add this line to your config file if the remote path for bundle install has spaces: .bundle\config:

BUNDLE_LOCAL__BCRYPT: C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\bcrypt-3.1.10\lib

  1. run bundle install
0

This is the simple solution that worked for me:

Tested on mac:

Ensure that gem 'bcrypt', '3.1.11' is in your gemfile then run xcode-select --install. Run bundle install

That's it.

Best of lucks

Wilson
  • 71
  • 4
0

I encountered the same error. I resolved it by stopping my server and running bundle install. Make sure your server is not running while executing the command bundle install

Faizan
  • 1
  • 2
-2

Gems with extensions written in C, like bcrypt, won't always compile on different platforms/ruby versions. You could look for a pure ruby alternative to bcrypt and avoid possible issues with C extensions altogether. You could also try a different version of the gem and see if it compiles on your system.

Andrew Prentice
  • 275
  • 2
  • 7