Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

Install Ruby, Rails, and PostgreSQL on OSX

Posted by Robby Russell Mon, 29 May 2006 14:46:00 GMT

52 comments Latest by wholesale caps Thu, 02 Sep 2010 11:44:13 GMT

WARNING: This post contains some outdated instructions. Please read Installing Ruby on Rails and PostgreSQL on OS X, Second Edition.

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.
In this step we are going to modify the default bash profile so that every user on the machine that uses bash will get the path for darwinports in their bash_profile.
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!

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    atmos Mon, 29 May 2006 16:30:27 GMT

    I did a similar writeup but did a few things differently. :) You can check out my macbook pro how-to here .

  2. Avatar
    Xenith Mon, 29 May 2006 21:21:14 GMT

    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
  3. Avatar
    David Tue, 30 May 2006 14:36:32 GMT

    Just a minor correction: It’s spelled Xcode, not XCode. Seriously, nobody calls you RObby, do they?

  4. Avatar
    Jacob Harris Tue, 30 May 2006 19:02:36 GMT

    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.

  5. Avatar
    Al Hulaton Wed, 31 May 2006 14:40:42 GMT

    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!

  6. Avatar
    David Salgado Sat, 03 Jun 2006 08:47:44 GMT

    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;

    sudo port install autoconf
    sudo port install ruby rb-rubygems

    Thanks again.

    David

  7. Avatar
    Jim Greer Wed, 07 Jun 2006 04:21:04 GMT

    Works for me!

  8. Avatar
    Chris Wed, 14 Jun 2006 19:10:28 GMT

    For a new developer, this site is so useful. Tips like these that help me streamline my own forming processes. Thanks!

  9. Avatar
    zorph Thu, 22 Jun 2006 02:28:18 GMT

    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)

  10. Avatar
    chris Sat, 24 Jun 2006 18:54:05 GMT

    Thanks for the help.

    Good stuff.

  11. Avatar
    Joe Sun, 25 Jun 2006 20:19:03 GMT

    Well, since it’s aPple, why isn’t it xCode?

  12. Avatar
    Dan B Sun, 09 Jul 2006 21:05:47 GMT

    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

  13. Avatar
    Manjoor Thu, 13 Jul 2006 10:58:26 GMT

    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

  14. Avatar
    Manjoor Thu, 13 Jul 2006 10:59:03 GMT

    hi

  15. Avatar
    Manjoor Thu, 13 Jul 2006 11:00:30 GMT

    mail me at manzoor@aboutd.com phone me at +91-9829298623 india. i wat ur mail or phone

  16. Avatar
    yonas Thu, 12 Oct 2006 18:25:59 GMT

    thanks much! worked like a charm.

  17. Avatar
    krakholiya@gmail.com Tue, 19 Dec 2006 12:34:16 GMT

    from where to download package of ‘RMagick.gem’ plz send me url i will be very thank full to you

    actully i have to upload photo and mydatabase is mysql and i am very very new programmer i only made one CRUD application plz tell me how do i solve this problem..

    thanx

  18. Avatar
    Martin Tue, 09 Jan 2007 17:10:41 GMT

    mostly from other sites

  19. Avatar
    Justin Myers Fri, 19 Jan 2007 12:34:10 GMT

    Thank you for this tutorial. I appreciated it a lot. My notes:

    postgresql82 is now out as a darwinport and I used that.

    I used Xenith’s (see above note) instructions during my install of the postres gem and was successful except that adding a 2 to the end of pgsql8 doesn’t work because the directory is now called postgresql82.

  20. Avatar
    Ian Collins Fri, 02 Mar 2007 07:28:53 GMT

    I followed all of these instructions, and about 4 others I found linked here and other places online. No matter how I do this, I get the following error when I try and rake:

    rake aborted! no such file to load—postgres

    (See full trace by running task with—trace)

    I am using the same steps as Justin Myers (above), and get the success message “Successfully installed postgres-0.7.1” and everything (for the postgres gem).

  21. Avatar
    Jason Marc Tue, 06 Mar 2007 06:48:57 GMT

    Yeah, I get the same problem as Ian above. I did everything flawlessly, but I still get the no such file error when I try to rake db:migrate.

    Any insights as to why this is happening?

  22. Avatar
    Jason Marc Tue, 06 Mar 2007 23:49:27 GMT

    Ahh, ok, I got it. I reinstalled the gem using the explicit instructions in the body of the post, as opposed to the shortcut using sudo gem install postgress - -...

    Although it will say it installed successfully, in reality, it doesn’t, so you have to do some making and make installing on your own.

  23. Avatar
    Steve Sat, 10 Mar 2007 06:57:53 GMT

    Thanks for this, Robby. Just a note:

    Macports seems not to love Postgres any more. After trying and failing to download it I found it simpler to build from source. Fink also can successfully install but they are at 8.0.? so if you’re relying on bleeding edge, that won’t work.

    Here’s an article about installing the gem:

    http://tomcopeland.blogs.com/juniordeveloper/2006/01/installing_the_.html

    Here’s a where to get the source. Building couldn’t be simpler.

    http://www.postgresql.org/

    Just:

    ./configure
    make
    sudo make install

    Follow Robby’s instructions on how to test your installation.

  24. Avatar
    Robby Russell Tue, 19 Jun 2007 21:13:37 GMT Recommend me on Working with Rails

    UPDATE

    Please read the second edition of this article.

  25. kasino online Wed, 28 Nov 2007 00:44:03 GMT

    Spielen Sie Kasino online und amüsieren Sie sich dabei. Spielen Sie nicht zu viel, sonst ist das ganze Geld weg.

  26. Avatar
    Rob Fri, 11 Sep 2009 10:58:43 GMT

    I get the same problem as Ian above. I did everything flawlessly, but I still get the no such file error when I try to rake db:migrate.

  27. Avatar
    laptop battery supplier Thu, 13 May 2010 06:52:26 GMT

    so that we don’t hit too many issues when working together on projects.

  28. Avatar
    nike airmax 90 Tue, 25 May 2010 00:26:05 GMT

    hjghjghjn

  29. Avatar
    nike Zenyth shoes Tue, 25 May 2010 00:26:25 GMT

    jh

  30. Avatar
    supra thunder red Wed, 26 May 2010 06:32:36 GMT
    supra thunder red, supra thunder red
  31. Avatar
    nike zoom lebron iv Wed, 26 May 2010 06:33:21 GMT
    nike zoom lebron iv, nike zoom lebron iv
  32. Avatar
    air jordan 5 Fri, 28 May 2010 06:03:11 GMT

    tyututyu

  33. Avatar
    ed hardy sweaters Sat, 29 May 2010 07:36:12 GMT
  34. Avatar
    lebron ii Sat, 05 Jun 2010 02:17:58 GMT

    trytr y

  35. Avatar
    supra thunder red Sat, 05 Jun 2010 02:18:08 GMT

    tr ytr y

  36. Avatar
    2010 germany 16 lahm Sat, 05 Jun 2010 02:18:19 GMT

    tr yrty

  37. Avatar
    mbt sale Tue, 08 Jun 2010 08:08:41 GMT

    erter

  38. Avatar
    Adidas slipper Tue, 08 Jun 2010 08:08:50 GMT

    rt re t

  39. Avatar
    Adidas superstar APE Wed, 09 Jun 2010 03:11:49 GMT

    yu y

  40. Avatar
    Nike Zoom Soldier IV Wed, 09 Jun 2010 03:12:00 GMT

    yuiyui

  41. Avatar
    asdfa Mon, 21 Jun 2010 03:46:02 GMT

    Leaving out the username and ghd hair straightnerpassword in database.yml caused an error chi flat ironwhen I tried to rake migrate. When I put the username and password back in, it migrated! (I’m setting up rails vibram five fingers/postgresql on windows XP though)

  42. Avatar
    air jordan 11 Wed, 30 Jun 2010 08:58:03 GMT

    Demonstrate a unique new conceptjordan shoesAwA81

  43. Avatar
    air jordan 11 Wed, 30 Jun 2010 09:00:35 GMT

    Demonstrate a unique new conceptjordan shoesAwA81

  44. Avatar
    malin Wed, 07 Jul 2010 09:04:52 GMT
  45. Avatar
    Louis Vuitton Wallets Mon, 19 Jul 2010 18:01:41 GMT

    Louis Vuitton Astrid Wallet M61781 Louis Vuitton Astrid Wallet Louis Vuitton Boetie wallet M63220 Louis Vuitton Boetie wallet Louis Vuitton Sarah Wallet Monogram Etoile M66556Louis Vuitton Sarah Wallet Monogram Etoile Louis Vuitton Compact Wallet Monogram Etoile M63799Louis Vuitton Compact Wallet Monogram Etoile Louis Vuitton Elise Wallet M61654 Louis Vuitton Elise Wallet Louis Vuitton Sarah Wallet Fleuri M60232 Louis Vuitton Sarah Wallet Fleuri Louis Vuitton Sarah Wallet Fleuri M60233 Louis Vuitton Sarah Wallet Fleuri Louis Vuitton Sarah Wallet Fleuri M60234 Louis Vuitton Sarah Wallet Fleuri Louis Vuitton Sarah Wallet M61734 Louis Vuitton Sarah Wallet Louis Vuitton Alexandra wallet M60047 Louis Vuitton Alexandra wallet Louis Vuitton Insolite Wallet PM Fleuri M60229 Louis Vuitton Insolite Wallet PM Fleuri Louis Vuitton Insolite Wallet PM Fleuri M60230 Louis Vuitton Insolite Wallet PM Fleuri Louis Vuitton Insolite Wallet PM Fleuri M60231 Louis Vuitton Insolite Wallet PM Fleuri Louis Vuitton Insolite Wallet Fleuri M60226 Louis Vuitton Insolite Wallet Fleuri Louis Vuitton Insolite Wallet Fleuri M60227 Louis Vuitton Insolite Wallet Fleuri Louis Vuitton Insolite Wallet Fleuri M60228 Louis Vuitton Insolite Wallet Fleuri

  46. Avatar
    briefcase supplier Mon, 09 Aug 2010 03:20:30 GMT
    1. ails application directory. cd argon
    2. Generate a new model to test with: ./script/generate model Argonista
    3. Edit and save the m
  47. Avatar
    apple iphone for sale Wed, 11 Aug 2010 02:19:52 GMT
  48. Avatar
    tiffnay Wed, 11 Aug 2010 06:56:25 GMT

    Diamond is used for making tiffany jewellery, bracelets, earrings and many other things. Ornaments made of diamonds enhance person’s beauty and endurance. Among the different ornaments, earrings are the most important ornament that reveals thoughts of style, elegance and beauty of the wearer. The history of earrings has been around for nearly as long as when women and men started to groom themselves.

    Traditionally, a ring of gold, silver or other durable metals were worn through the earlobe by way of a piercing in the center of the lobe or by clipping but the popularity of earrings in this modern society especially diamond earrings has increase lately and is mostly preferred by the women.tiffany and co Diamond earrings are now considered as the best friend of a woman their ornament box looks incomplete in the absence of a variety of ear rings that are appropriate for different occasions. Women use earrings as fashion accessories, and they can be matched to a wide variety of outfits from formal evening attire, to more casual jeans or even a business suit. Whichever styles of you opt for diamond earrings, all of it represent classic style and elegance and also make a perfect gift for anyone near to your heart tiffany jewellery.

    Diamond earrings are given different kinds and shapes like diamond hoop tiffany bracelet, diamond heart earrings, drop diamond earrings and much more. Each of which are eye catcher. While shopping for diamond jewelry always make an effort to remember four C’s that are mainly constructed for diamond and is applied when crafting the finest diamond ornaments. They are cut, color, and clarity and carat weight. Diamond earrings with all the four characteristics are considered the best that speak out the wearer’s high-class taste and love for things of beauty. The more is the reflection of light from the surface of the diamond the more it sparkles which provides additional beauty to your whole get up. Even your ear will feel proud to possess such a beautiful tiffany jewellery uk diamond piece catching the attention of the onlookers otherwise who cares to look at your ears. tiffany jewellery tiffany and co tiffany bracelet tiffany bracelets tiffany necklace tiffany necklaces tiffany ring tiffany rings

  49. Avatar
    chanel handbags online Tue, 31 Aug 2010 04:01:03 GMT

    One of the more impressive blogs Ive seen. Thanks so much for keeping the internet classy for a change.

  50. Avatar
    vector conversion Tue, 31 Aug 2010 15:13:43 GMT

    Now, I feel good, I started take up real income. vector conversion have never thought that there weren’t any need in big initial investment.Keep working, great job, I love it! digitizing software Thanks.Great post. I have been searching for this exact info for a while now. I will bookmark it in the public bookmarking sites to get you more traffic. stock designs Now lets see if I can do something productive with it.Thanks so much for keeping the internet classy for a change.

  51. Avatar
    Matin Talen Thu, 02 Sep 2010 06:31:23 GMT
  52. Avatar
    wholesale caps Thu, 02 Sep 2010 11:44:13 GMT

    Your blog article is very intersting and fanstic,at the same time the blog theme is unique and perfect,great job.To your success.

Share your thoughts... (really...I want to hear them)

Comments