This is step 6 of Installing Ruby on a Mac and covers databases and Rails.
Getting Started
Step 1 - Xcode, Homebrew and Git
Step 2 - Wget and OH MY ZSHELL
Step 3 - RVM
Step 4 - Ruby
Step 5 - Gems and Pow
_Step 6 – Databases and Rails_
Hello World
Databases
Ruby on Rails has built-in support for SQLite3 and uses it as a database engine by default. Here’s the description from the SQLite site:
“A software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.”
SQLite is an embedded database which can be easily deployed with your application. There’s no database server to connect to and data is accessed through a single database file. For more info, check out the quick-start guide available on the site.
Lucky for us Mac OS X already comes with SQLite3:
Output:
3.7.5
If you have a version greater than 3.6.16 or newer then you good to go.
Go ahead and install the SQLite-Ruby module which lets Ruby applications (e.g. Rails) interface with SQLite3:
Output:
Fetching: sqlite3-1.3.5.gem (100%)
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Installing ri documentation for sqlite3-1.3.5...
Installing RDoc documentation for sqlite3-1.3.5...
You now have the necessary Ruby bindings to work with SQLite and Rails.
Of course Ruby can work with other databases, MySQL being the most popular one (install using Homebrew), but for now I’ll stick to SQLite as it is relatively easy to get started with for development and testing.
Rails
We’re almost there. The only thing left for us to do is to install Ruby on Rails. If you’re starting Ruby development no doubt you know already about it so I’ll quickly move on.
We’ll use gem to install Rails:
This can take a little while as RubyGems has to download and install not only Rails but also other gem dependencies.
On completion, check that the version is 3.1.1 or higher:
Wow… This was the shortest step :)
We’re now in a position to write the canonical ”Hello World” Rails application…
If you see any inaccuracies, things that should be added, removed or corrected, please either leave a comment or drop me an email. Thanks.