Install Ruby, Rails, and PostgreSQL on OSX
15 comments Latest by Manjoor Thu, 13 Jul 2006 10:00:30 GMT
Our Creative Director, Allison Beckwith, picked up a new black MacBook this weekend and I had the luxury of getting it setup to model our standard setup. We all try to keep our setups fairly similar so that we don’t hit too many issues when working together on projects.
I’ll try to keep this short and to the point… because if you’re like me… you just want to start playing with Rails! ;-)
The steps I followed to get her setup like the rest of the development team at PLANET ARGON went something like this.
XCode and DarwinPorts
- Download and install iterm (the Universal dmg)
- Download and install XCode tools from Apple (dmg)
- Download and install DarwinPorts (dmg)
- Start up iterm.
sudo vi /etc/profile
Modify the following line to include /opt/local/bin
in the PATH… save the file (see vim documentation for details)
PATH="/bin:/sbin:/opt/local/bin:/usr/bin:/usr/sbin"
Ruby and Rails
- Open up a new iterm tab (apple-t)
- Install ruby with darwinports with:
sudo port install ruby rb-rubygems
- Install Ruby on Rails and all its dependencies with:
sudo gem install -y rails
PostgreSQL and Ruby libs
- Install PostgreSQL8 with:
sudo port install postgresql8
- We need to modify the
/etc/profile
file again because the postgresql8 install doesn’t add programs like pg_ctl to /opt/local/bin. Change the PATH to now look like this and save.
PATH="/bin:/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/lib/pgsql8/bin"
- Install the postgres gem with:
sudo gem install postgres
- Oh NO!!! You should see an error about it not finding libraries… what will we do?
cd /opt/local/lib/ruby/gems/1.8/gems/postgres-0.7.1
sudo ruby extconf.rb --with-pgsql-include=/opt/local/include/pgsql8 --with-pgsql-lib=/opt/local/lib/pgsql8
sudo make && sudo make install
# for good measure...
sudo gem install postgres
Successfully installed postgres-0.7.1
Configure PostgreSQL for single user
In our development environments, we don’t find it necessary to keep PostgreSQL running all the time on our servers. We only want it running when we’re doing development. We also typically install it per user on a machine to keep us from needing things like usernames and passwords to connect to it from an application we’re running on the machine. Let’s setup PostgreSQL the PLANET ARGON way!
- Open up iterm and go to your home directory
- Init your new PostgreSQL database with:
initdb -D pgdata
- Start up PostgreSQL with:
pg_ctl -D pgdata -l pgdata/psql.log start
- Create a new database with:
createdb argon_development
- Test the new database with:
psql argon_development
- Did it load up your new database? If so, great! If not… check your steps… :-)
Test Rails + PostgreSQL
- Navigate to a directory where you don’t mind sticking projects…
mkdir development; cd development
- Generate a new Rails application with:
rails -d postgresql argon
- Navigate to new Rails application directory.
cd argon
- Generate a new model to test with:
./script/generate model Argonista
- Edit and save the migration that was generated (
db/migrate/001_create_argonistas.rb
) file with your favorite editor…
class CreateArgonistas < ActiveRecord::Migration
def self.up
create_table :argonistas do |t|
t.column :name, :string
t.column :blog_url, :string
end
end
def self.down
drop_table :argonistas
end
end
- Edit
config/database.yml
to look like the following… you’ll notice that we don’t need to supply a username or password.
development:
adapter: postgresql
database: argon_development
test:
adapter: postgresql
database: argon_test
production:
adapter: postgresql
database: argon_production
* Run the migration with: rake db:migrate
$ rake db:migrate
(in /Users/allisonbeckwith/development/argon)
== CreateArgonistas: migrating ================================================
-- create_table(:argonistas)
NOTICE: CREATE TABLE will create implicit sequence "argonistas_id_seq" for serial column "argonistas.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "argonistas_pkey" for table "argonistas"
-> 0.0399s
== CreateArgonistas: migrated (0.0402s) =======================================
* Test your new model from console
$ ./script/console
Loading development environment.
>> a = Argonista.new
=> #<Argonista:0x24569dc @attributes={"name"=>nil, "blog_url"=>nil}, @new_record=true>
>> a.name = 'Robby'
=> "Robby"
>> a.blog_url = 'http://www.robbyonrails.com'
=> "http://www.robbyonrails.com"
>> a.save
=> true
>> exit
* Great, let’s go look at our database table…
$ psql argon_development
Welcome to psql 8.1.3, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
argon_development=# SELECT * FROM argonistas;
id | name | blog_url
----+-------+-----------------------------
1 | Robby | http://www.robbyonrails.com
(1 row)
There we go, we’ve setup Ruby, Rails, and PostgreSQL on a brand new Intel MacBook without breaking a sweat!
Extra Goodies
- Subversion:
sudo port install subversion
- Lighttpd:
sudo port install lighttpd
- ImageMagick:
sudo port install ImageMagick
(known to take a while…) - GraphicsMagick:
sudo port install GraphicsMagick
- Install the rmagick gem:
sudo gem install rmagick
Have fun!
I did a similar writeup but did a few things differently. :) You can check out my macbook pro how-to here .
There’s no need to recompile the postgres gem. You can pass the configure options straight to the gem using
--
as so:sudo gem install postgres -- --with-pgsql-include=/opt/local/include/pgsql8 --with-pgsql-lib=/opt/local/lib/pgsql8
Just a minor correction: It’s spelled Xcode, not XCode. Seriously, nobody calls you RObby, do they?
FYI, there was an issue where Postgresql would fight with iChat for shared memory when you attempted to do a video chat (it would get a signal fine from the iSight for preview, but then complain there was no signal when a chat is initiated). There is a fix on the Interwebs, but I figured I’d let you know in case allisbe’s iChat starts acting up.
Very timely article. I just got a Macbook Pro and was about to muddle through the postgres install. Now I can just copy your homework. Thanks!
Very useful article – many thanks.
On my Powerbook running Panther, I got a complaint about autoconf versions when trying to do “sudo port install ruby rb-rubygems”.
To fix this, simply;
Thanks again.
David
Works for me!
For a new developer, this site is so useful. Tips like these that help me streamline my own forming processes. Thanks!
Leaving out the username and password in database.yml caused an error when I tried to rake migrate. When I put the username and password back in, it migrated! (I’m setting up rails/postgresql on windows XP though)
Thanks for the help.
Good stuff.
Well, since it’s aPple, why isn’t it xCode?
Nice writeup. I’m having problems with getting ruby and postgresql installed. They both depend on readline and darwinports cannot install readline:
mac:~ mac$ sudo port install readline Password:
-> Fetching readline -> Attempting to fetch readline51-001 from ftp://ftp.cwru.edu/pub/bash/readline-5.1-patches/ -> Attempting to fetch readline51-001 from http://distfiles-od.opendarwin.org/ -> Attempting to fetch readline51-001 from http://distfiles-msn.opendarwin.org/ -> Attempting to fetch readline51-001 from http://distfiles-bay13.opendarwin.org/ Error: Target com.apple.fetch returned: fetch failed Error: /opt/local/bin/port: Status 1 encountered during processing. mac:~ mac$
I did find a readline tar-ball here: ftp://ftp.gnu.org/gnu/readline/readline-5.1.tar.gz
Is there any way I can graft it on to /opt/local so that ports [ ruby for example ], which depend on it can get installed?
Thanks, -Dan
hi isr i am manjoor alihere i want asoftware Cd of postgreSQl version 8.1.3 sir plz help me to run my project to it because it uninstall on my PC your friend Er. Manjoor Ali
hi
mail me at manzoor@aboutd.com phone me at +91-9829298623 india. i wat ur mail or phone