0
votes

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
6
try "bundle install; bundle exec rails server"? or "gem install sqlite3" ?Spike Gronim
Is that really the whole Gemfile? Shouldn't there be a source at the top? Are you not showing that bit?Craig Stuntz
@Craig Stuntz I am only showing a bit since it has many lines of code. Do you want me to paste the complete GemFile?azamsharp
@Spike Gronim I run gem install sqlite3 and got the error message. Please see the update 1.azamsharp
You don't need to paste the whole gemfile, but since it tells you it couldn't fin SQLite in the sources you have, it might help to list those!Craig Stuntz

6 Answers

3
votes

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

2
votes

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.

1
votes

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.

0
votes

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.

0
votes

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.