16

I'm trying to install the "sqlite3-ruby" gem (or the "sqlite3" gem) on OS X 10.6. I'm using ruby-1.9.2 and I currently get the following:

 $ sqlite3 --version
3.7.4
 $ sudo gem install sqlite3
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

/Users/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for sqlite3.h... *** 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
    --without-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/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
/Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:28:in `<main>'


Gem files will remain installed in /Users/folken/.rvm/gems/ruby-1.9.2-head/gems/sqlite3-1.3.3 for inspection.

The following is the results of which & whereis, and the sqlite3.h is located in /opt/local/include:

 $ which sqlite3
/opt/local/bin/sqlite3
 $ whereis sqlite3
/usr/bin/sqlite3

I've tried passing in the following as well:

sudo gem install sqlite3 -- --with-sqlite3-include /opt/local/include --with-sqlite3-lib /opt/local/lib
sudo gem install sqlite3 -- --with-sqlite3-dir /opt/local/bin

which results in the following:

ERROR:  Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

/Users/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb --with-sqlite3-dir /usr/bin/sqlite3
*** 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
    --without-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/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby
    --with-sqlite3-dir
/Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:1336:in `dir_config': undefined method `split' for true:TrueClass (NoMethodError)
    from extconf.rb:9:in `<main>'

Also under /Users/folken/.rvm/gems/ruby-1.9.2-head/gems: sqlite-ruby-2.2.3 sqlite3-1.3.3

Under RVM I have ruby-1.8.7 and the sqlite3 gem loads fine on that, but after much googling I have not found a solution that works for me. Any help is greatly appreciated (even if it involves manual installation / hackery to get working).

Folken
  • 437
  • 2
  • 7
  • 13
  • 1
    Did you check the makefile log like it told you? What did it contain? – jergason Feb 17 '11 at 06:23
  • Do you have gcc? Try typing gcc in your shell – Michael Papile Feb 17 '11 at 06:27
  • 1
    @Michael - yes I have gcc, @Jergason - I'm not sure where this mkmf.log file is being outputted, it isn't under /Users/folken/.rvm/log/ruby-1.9.2-head (or anywhere near, where is it typically dumped to?) – Folken Feb 17 '11 at 06:55
  • 2
    Have you installed Sqlite dev library, on Ubuntu do "sudo apt-get install libsqlite3-dev" – Zimbabao Feb 17 '11 at 09:35
  • 1
    @Zimbabao - I've installed sqlite3-dev using apt-get install, but I'm on OS X (I just edited the original post to add OS X). – Folken Feb 17 '11 at 13:18
  • I just executed following command on my Mac OS X 10.5 "sudo gem install sqlite3 -- --with-sqlite3-lib=/opt/local/lib/" and it was installed. – Zimbabao Feb 17 '11 at 15:34
  • @Zimbabao - yea that works under the system ruby (ruby-1.8.1) but not under ruby-1.9.2 (which gives the errors in the original post) – Folken Feb 18 '11 at 04:02
  • Well I suppose I "fixed" it, not really though - I did an rvm install of ruby-1.9.2-p0 (I've been using ruby-1.9.2-head), then created a gemset for rails3, a regular gem install of sqlite3-ruby with no options passed in finishes successfully. – Folken Feb 18 '11 at 05:12
  • A further addition, my ruby versions: ruby-1.8.7-p302 [ x86_64 ], ruby-1.9.2-head [ i386 ], ruby-1.9.2-p0 [ x86_64 ] -- this explains why ruby-1.9.2-head wasn't working: i386 vs x64_64 – Folken Feb 18 '11 at 05:20
  • PS - to find a file on a unix-like system, go to your root directory and type "find . -name mkmf.log" It will take a while to run because it's checking every directory, but if the file exists - it'll find it. look up man find for more details... – Taryn East May 30 '11 at 10:27
  • Are you sure you want to use sudo if you are using rvm? – Francisco Soto May 31 '11 at 21:47

4 Answers4

15

I had an almost similar problem as you where I had sqlite3 installed and yet the sqlite3 gem would not install. I was seeing an error message as follows,

user-name-rajas-macbook-pro:rails3 user-namer$ gem install sqlite3
Building native extensions.  This could take a while...
    ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

        /Users/user-namer/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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/user-namer/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
    --with-sqlite3lib
    --without-sqlite3lib


Gem files will remain installed in /Users/user-namer/.rvm/gems/ruby-1.9.2-    p180@rails_3/gems/sqlite3-1.3.3 for inspection.
Results logged to /Users/user-namer/.rvm/gems/ruby-1.9.2-p180@rails_3/gems/sqlite3-    1.3.3/ext/sqlite3/gem_make.out

Here is what worked for me

gem install sqlite3 -- --with-sqlite3-dir=/opt/local
Moiz Raja
  • 5,082
  • 6
  • 34
  • 48
  • Thanks for this, I had a heck of a time figuring this one out. – adriandz Aug 04 '11 at 10:01
  • Many Thanks, this saved another hours agony! – Wasabi Oct 15 '11 at 02:03
  • The first lot of -- characters seems to do the trick! Just this --with-sqlite3-dir=/usr (brew installed sqlite3) does not work, but prefixing with -- seems to work. – pchap10k Mar 23 '12 at 05:10
  • what does the the extrea -- do? – Michael Z Jul 28 '12 at 05:56
  • The -- is a separator that is followed by build flags which help compile any native code that the gem depends on. Run 'gem help install' from your console - it gives a pretty good explanation of the options. – Moiz Raja Aug 01 '12 at 18:34
6

I was following the Rails3 in Action book with rvm using ruby 1.9.2.p180 and rails 3.1.0.rc6 using Mac OS X 10.5.8 (Leopard) and when I ran:

rake cucumber:ok

I got:

Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.4, runtime), already activated sqlite3-1.3.3. Make sure all dependencies are added to Gemfile.) 

I then did:

gem install sqlite3 -- --with-sqlite3-dir=/opt/local

Followed by:

bundle install

Hopefully, I will find my own answer on the Internet when sqlite 1.3.5 is required.

Jim Oser
  • 61
  • 1
  • 3
3

Sounds like you haven't installed XCode.

Sam Grossberg
  • 1,296
  • 1
  • 13
  • 28
2

For osx, make sure you have Xcode installed and you have accepted the terms. For me, I had not agreed to the terms (for whatever reason, perhaps Xcode was recently installed or updated on my computer).

  1. Open Xcode
  2. If a pop up appears then agree to the terms (if you do not get a pop up then you probably have already accepted the terms).
Logan Rice
  • 73
  • 4