How to install uuid4r using homebrew, rvm and bundle

So, I just ran into the problem of installing the uuid4r gem while setting up my development environment for a Rails app. 

While running `bundle install`, I was getting this error:

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

        /Users/miguel.parramon/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for uuid_export() in -luuid... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more details.  You may need configuration options.


Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/miguel.parramon/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
--with-uuidlib
--without-uuidlib
OSSP uuid library 'uuid' required -- not found.


Gem files will remain installed in /Users/miguel.parramon/.rvm/gems/ruby-1.9.3-p392@payments_gemset/gems/uuid4r-0.1.2 for inspection.
Results logged to /Users/miguel.parramon/.rvm/gems/ruby-1.9.3-p392@payments_gemset/gems/uuid4r-0.1.2/ext/gem_make.out

So, first of all, I installed the `ossp-uuid` formula with Homebrew:

brew install ossp-uuid

Homebrew installed the formula correctly, but since it is a keg-only formula, it gave me a warning like this one:

This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this program and installing another version in parallel can cause all kinds of trouble.

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need to add its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxslt/1.1.26/lib
    CPPFLAGS -I/usr/local/Cellar/libxslt/1.1.26/include


Then, I used the paths in that warning, together with the provided configuration options suggested by `extconf.rb`, to construct this line:

bundle config build.uuid4r --with-opt-include=/usr/local/opt/ossp-uuid/include --with-opt-lib=/usr/local/opt/ossp-uuid/lib

Which instructs bundler to pass those paths to `extconf.rb` when building the native extension for the `uuid4r` gem. I got the idea from here.

Then I ran:

`bundle`

And it worked! The `uuid4r` gem was installed correctly :D

4 comments:

  1. Thanks Miguel, that helped me a lot!
    Ronny

    ReplyDelete
  2. Excellent value driven article here. Tons of information. Appreciate it.
    Social Media Marketing

    ReplyDelete
  3. I hope you will share such type of impressive contents again with us so that we can utilize it and get more advantage.
    Canada Sex Toys

    ReplyDelete