I am following this guide ATM - http://guides.rubyonrails.org/getting_started.html#getting-up-and-running-quickly-with-scaffolding
When trying to create a database, I got:
Morgans-Computer:blog Morgan$ rake db:create
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run bundle install
to install missing gems.
When I try to run 'bundle install', I get more errors:
Installing sqlite3 (1.3.4) with native extensions /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
I have tried to install the Ruby Gem Sqlite3 (http://rubygems.org/gems/sqlite3-ruby) but it continues to fail. I found another post on here saying that I need to install C because that is what the compiler is written in? Wasn't sure exactly what that meant, or how I go about doing it.
Any help would be greatly appreciated!!
If you don't already have homebrew installed, I would set that up first. It's a nice package manager and allows you to install things like sqlite with brew install sqlite
.
To install brew you'll need xcode installed. If you don't already have that you'll probably need the cd that came with you system, or you can download from apple's website. On the latest OS, you can install it from the App Store which is nice (This might work for you too).
If you have mysql and would prefer to use that instead and sidestep the sqlite issue you can generate your rails project as such.
rails new my_new_project -d mysql
When you install the sqlite adapter gem, it has to compile code. To compile the code, it needs access to the sqlite development libraries.
This Rails on Mac OS X tutorial explains how to do it. Here is the most immediately relevant part:
sudo chown -R `whoami` /usr/local #make sure we have correct permissions to install sqlite
brew install sqlite
gem install sqlite3
On Mac, you'll probably want to install Xcode. You will also likely need some other packages for sqlite3
, which you should be able to get through MacPorts (ports: sqlite3
+ rb19-sqlite3
).
If you already have Xcode installed, go to the MacPorts Install page, download and install the provided .dmg
. Then you should be able to run this from the console to install the necessary packages:
sudo port install sqlite3 rb19-sqlite3
You can also use Homebrew, as others have suggested.