Scrypt Gem Native Extension Build Errors

Scrypt Gem Native Extension Build Errors

Gem installation errors can be very frustrating for Ruby beginners and advanced users alike.

Recently I encountered a gem installation error on OSX Mavericks with a fresh install and brand new macbook pro.

ERROR: Failed to build gem native extension.

I recieve this error during a bundle install of a rather large project. The gem in question was scrypt. Some people may recognize that gem as being an alternative gem for encryption of data. The usual gem used for this is bcrypt, but some project choose to go with the more secure but less often used scrypt.

The C libs that are used for this particular gem need gcc 4.2 to be install on your system and aliased to CC. Unfortunately on brand new macbook pros you will not have this particlar version of the gcc compiler installed. To resolve this issue you will need to install and alias the correct version of the gcc compiler. My recommended method for this is using homebrew to install gcc 4.2

brew tap homebrew/dupes
brew install apple-gcc42

The above commands will add the homebrew tap which contains the forumula for apple-gcc42

Once you add this tap and install the gcc42 compiler you can follow up with exporting CC to equal gcc-4.2 and installing the gem that experiencing the extension build error, in this case its scrypt.

export CC=gcc-4.2
gem install scrypt

The gem should install properly and clear up that nasty extension build error.