Tuesday, December 25, 2012

Guide to install RVM, Rails, Git, PostgreSQL and Heroku on Mac OS X Mountain Lion

Well, this is very easy. There is no even need to publish an article for this but the PostgreSQL is tricky and deserve to have some notes of how to have an Rails environment in Mac OS X and ready for Heroku.

Ruby is already installed in Mac OS X however it is highly recommended to use RVM and the best way to have RVM, Ruby, Rails and Git easily is with RailsInstaller. Go to the railsinstaller.org and just follow the instructions to download and install it. There is no need to repeat the instructions here, there is enough and very good documentation of how to proceed.

After that, you'll have all the rails environment ready. In case you want to confirm just execute the following commands:

type rvm | head -1                                         #Confirm RVM is installed
#The output should be:
#  rvm is a function
rails new demo
cd demo
rails s
#Go to http://localhost:3000

Let's go with PostgreSQL which is already installed in Mac OS X Mountain Lion. Why PostgreSQL? Because it is required by Heroku. The easier way to have it running is installing Postgresapp. Download it and copy it to your Application directory and execute it.

Now the tricky part. As PostgreSQL is already installed in your Mac by default you need to make sure the OS use Postgresapp instead of the default PostgreSQL. Not doing this will cause several errors from now on.

Modify the PATH variable in your ~/.profile or ~/.bash_profile file to add the Postgres.app bin directory.

#Add PostgreSQL from Postgres.app to PATH
export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH 

To test it is running execute the following command and then install the pg gem.

which psql
#/Applications/Postgres.app/Contents/MacOS/bin/psql
psql --version
# and try to connect to localhost
psql -h localhost
gem install pg

Setup Heroku first install Heroku Toolbelt. Then log in using your heroku credentials (email address and password).

$ heroku login
Enter your Heroku credentials.
Email: 
Password (typing will be hidden): 
Authentication successful.

Now in every RoR application you need to replace in the Gemfile the use of sqlite by pg, at least for production environment (recommended for all).

Post a Comment