ruby-on-railspostgresqlruby-on-rails-3.1osx-snow-leopard

Setup Rails 3.1 and Postgresql on Snow Leopard


I have spent countless number of hours trying to setup PostgreSql on my Intel Mac.

I am able to install Rails and all but PostgreSql would not get installed on my Mac.

Anybody has any solution or any tutorial which I can follow to install it ??

P.S. I just started using Mac as my development machine. I have been using Windows before that !


Solution

  • Ok I had to do a little more research with a fresh mind and I am now able to solve the problem myself. Here is the solution :

    Install Homebrew using this command :

    ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
    

    Once installed write this in your terminal :

    brew install postgres
    

    If this is your first install ( which was the case with me ) than type this in terminal after the above step:

    $ initdb /usr/local/var/postgres
    

    To start the postgresql type this in terminal:

    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
    

    After the above step type this :

    ps auxwww | grep postgres
    

    If the result of the above command in terminal looks like this than that means the postgresql is installed correctly :

    26000   0.0  0.1  2445860   1556   ??  Ss    1:59AM   0:00.05 postgres: autovacuum launcher process
    25999   0.0  0.0  2445728    512   ??  Ss    1:59AM   0:00.15 postgres: wal writer process
    25998   0.0  0.0  2445728    912   ??  Ss    1:59AM   0:00.21 postgres: writer process  
    
    25996   0.0  0.1  2445728   2508   ??  S     1:59AM   0:00.15 /usr/local/Cellar/postgresql/9.0.4/bin/postgres -D /usr/local/var/postgres
    
    26257   0.0  0.0  2435548      0 s000  R+    2:19AM   0:00.00 grep postgres
    

    Create a user and database:

    createuser username
    
    createdb -Ousername -Eutf8 databasename
    

    To login to postgresql use this command:

    psql -U username databasename
    

    If you are using it with rails you can install the gem like this :

    sudo env ARCHFLAGS="-arch x86_64" gem install --no-ri --no-rdoc pg
    

    If you would like to stop the PostgreSQL service use this command :

    pg_ctl -D /usr/local/var/postgres stop -s -m fast
    

    Hope this will help others in saving the time of going through different resources to come with the solution like I did :)