0

When I run 'rails server' I get the following error:

Could not find gem 'sqlite3 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

My GemFile looks like this: gem 'sqlite3'

Also when I run the port command it says it does not recognize that command:

Mohammad-Azams-MacBook-Pro:blog azamsharp$ port install sqlite3 +universal
-bash: port: command not found

Any suggestions?

UPDATE 1:

I run sudo gem install sqlite3 and got the following message:

Mohammad-Azams-MacBook-Pro:blog azamsharp$ sudo gem install sqlite3
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

/usr/local/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.

UPDATE 2: (Contents of GemFile)

source 'http://rubygems.org'

gem 'rails', '3.0.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

UPDATE 3:

Mohammad-Azams-MacBook-Pro:blog azamsharp$ port search sqlite3 -bash: port: command not found

UPDATE 4:

After downloading the install Macports I ran the bundle install again and here is the result:

Installing sqlite3 (1.3.3) with native extensions /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:inbuild_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/usr/local/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.

`

UPDATE 5:

which sqlite3 gives me the following:

Mohammad-Azams-MacBook-Pro:blog azamsharp$ which sqlite3
/opt/local/bin/sqlite3

UPDATE 5:

which -a sqlite3 gives me the following:

Mohammad-Azams-MacBook-Pro:blog azamsharp$ which -a sqlite3
/opt/local/bin/sqlite3
/usr/local/bin/sqlite3
/usr/bin/sqlite3
azamsharp
  • 19,710
  • 36
  • 144
  • 222

6 Answers6

3

If you have problems talking about /usr/local/bin/ruby extconf.rb checking for sqlite3.h then it's probably something to do with macports.

First, make sure you have xcode installed. Run:

gcc

and you should get:

i686-apple-darwin10-gcc-4.2.1: no input files

If you do, then let's install homebrew

Then, a list of commands to install homebrew, update rubygems, and upgrade rails

brew install sqlite
gem update --system
gem install bundler
gem install rails -v=3.0.8

Then, to check, rails -v should output Rails 3.0.7

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
2

If you are running 10.4 or earlier you don't have sqlite 3 (the actual DB engine, not the gem) installed by default. You have 3 options (assuming upgrading your OS to 10.5 or 10.6 is not an option):

  1. Compile the source (not as bad as it sounds) http://www.sqlite.org/download.html
  2. Install MacPorts (why the port command was not found) http://www.macports.org/install.php
  3. Don't use sqlite. Instead use mysql or another DB of your choice.

I recommend the latter if you are going to deploy using some DB other than sqlite, and deploying with sqlite generally isn't a good idea. I like to keep my development and production environments fairly uniform to help avoid gotchas and such.

I hope this helps.

brettish
  • 2,628
  • 3
  • 17
  • 22
  • I am running Mac OSX 10.6.6 and I have used sqlite3 on this mac before but I think I updated my rails engine and now it does not seems to work. – azamsharp Jun 02 '11 at 17:34
  • @azamsharp Reading the other comments and answers, I don't know quite what to say. My 10.6 box works just fine. This is a long shot, but try updating to the most recent developer tools. The "free" version is still available. That is what I have. If all else fails, then I fall back on recommendation #3... unless you plan to deploy with sqlite :-) Hopefully someone else in SO will have some more helpful advise. – brettish Jun 02 '11 at 20:33
  • I gave up on sqlite3 and tried mysql and same problems. Now I am looking into MongoDb. – azamsharp Jun 02 '11 at 20:53
  • @azamsharp if you are having the same trouble with mysql then something is definitely wrong with your computers configuration and looking at other DB's will probably not fix the problem. – brettish Jun 02 '11 at 22:08
1

I'm summing up in a reply. So :

1) Install macports : http://www.macports.org/install.php - It has a dmg installer, will take 2 minutes.

2) Once you have it installed, do a 'bundle install' and sqlite3 will be installed as specified in your Gemfile.

Spyros
  • 46,820
  • 25
  • 86
  • 129
  • I downloaded the MacPorts and install Macports. Then I ran the command 'sudo port install sqlite3 +universal'. It installed a bunch of stuff along with sqlite3. But even now when I says 'rails server' it gives me the same error 'could not find gem sqlite3' – azamsharp Jun 02 '11 at 18:21
  • Yes I just did! Please see the Update 4. – azamsharp Jun 02 '11 at 18:45
  • You may need to bundle update sqlite3 now that your binaries are installed – Jesse Wolgamott Jun 03 '11 at 00:22
0

When you use port look for a package called sqlite3-dev or something similar to that. The -dev part is key. I don't use MacPorts, but on my Ubuntu install this is the needed package.

When you want to install a package that you plan to link against, always look for the -dev version. The -dev means that it installs the header files among other things that are needed for development against that package.

Most likely your gem cannot build the sqlite3 native extension because it is looking for the header files, if this does not solve your problem please post the log file for the gem installation.

  • Looking more closely at the updates above, it seems that it was able to find you sqlite header file. If you could post the output from mkmf.log that would help me see what the problem with the compilation is. – Aaron D. Jun 06 '11 at 21:45
0

From your Rails directory:

cd ..
cd rails-root
ruby -v
gem list sqlite3
bundle install
gem list sqlite3
bundle exec rails server

What might be happening is you're bundling in a Rails app that has an .rvmrc file. I've seen cases where you bundle under a version of Ruby that doesn't match the .rvmrc file or some other mismatch so when you bundle sqlite3 it isn't under the same version of Ruby that rails is using when you run the app.

Changing out of the directory and back into it, and running rails server prefixed with bundle exec are my two suggestions.

Dan Croak
  • 1,639
  • 13
  • 13
-1

there were several links about your problem :

Community
  • 1
  • 1
Agung Prasetyo
  • 4,353
  • 5
  • 29
  • 37