Skip to content

Instantly share code, notes, and snippets.

@eubenesa
Forked from monicao/notes.md
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eubenesa/d1128f8c4b594710ccd6 to your computer and use it in GitHub Desktop.
Save eubenesa/d1128f8c4b594710ccd6 to your computer and use it in GitHub Desktop.

Setting up the Ruby dev environment on Mavericks

Why would I want to do that?

  • You want to run guard
  • You want use Sublime plugins (like RSpec or Guard plugins)

Installing brew

Brew aka Homebrew is a package management system for Mac OSX.

Open up the Mac Terminal and run this command to install brew on your mac:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Install ruby through rbenv

Now that we have Homebrew installed, we can use it to install Ruby.

We're going to use rbenv to install and manage our Ruby versions. rbenv makes it really easy to have several versions of ruby on your laptop and switch between them.

To do this, run the following commands in your Terminal:

brew install rbenv ruby-build

# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

# Install Ruby 2.1.1 and set it as the default version
rbenv install 2.1.1
rbenv global 2.1.1

ruby -v
# ruby 2.1.1

Check out this article for a list of rbenv commands: http://cbednarski.com/articles/installing-ruby/

Install rails

Install rails on your system so you can create new rails projects.

gem install rails

Rails is now installed, but in order for us to use the rails executable, we need to tell rbenv to see it:

rbenv rehash

And now we can verify Rails is installed:

rails -v
# Rails 4.1.1

Install the Postgres.app

"The easiest way to run Postgres on your Mac"

http://postgresapp.com/

You can also install and start Postgres using Homebrew:

brew install postgresql
brew services start postgresql

Install the pg gem

Here's how to install the pg gem with Postgres.app. http://stackoverflow.com/questions/20224483/cannot-install-pg-gem-in-mavericks-with-postgres-app

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

Install the command line developer tools

If you have XCode < 5.1.1

The nokogiri gem needs these. See here for details: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/

xcode-select --install

If you have XCode > 5.1.1

Follow these instructions: http://stackoverflow.com/questions/23260748/manual-install-of-xcode-command-line-tools-not-working

  1. Open XCode
  2. Click on Xcode > Open Developer Tools > More Developers Tools This will take you to the Downloads for Apple Developers web site. Use your AppStore Id to login.
  3. Download Command Line Tools for your Mac OS X version. (Probably Mavericks April / March 2014). http://monicao.s3.amazonaws.com/gist_images/Screen%20Shot%202014-07-01%20at%2012.42.06%20PM.png

See if it worked

gem install nokogiri

Install the gems for a Rails project

  cd /Users/monica/lighthouse/laser_shark
  bundle install

Follow the other setup instructions for that rails app. For laser_shark, you will have to edit your /etc/hosts, for example.

Change database.yml

In config/database.yml, make sure you have the following settings. Make sure you have the host, the password is blank, and the username is set to your computer's username. If you are not sure what your computer's username is, try running whoami in the terminal.

development:
  adapter: postgresql
  database: your_project_development
  host: localhost
  encoding: unicode
  pool: 5

test:
  adapter: postgresql
  database: your_project_test
  host: localhost
  encoding: unicode
  pool: 5

Here's my database.yml for a rails project called hooligans

development:
  adapter: postgresql
  database: hooligans_development
  host: localhost
  encoding: unicode
  pool: 5

To check if this works, see if you can create the database.

bin/rake db:create

Troubleshooting

Could not connect to server: Connection refused

If you see this error, make sure Postgres.app is started. You should see an elephant icon in your mac's top bar.

SYS:laser_shark SYS$ bin/rake db:create
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
/Users/SYS/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize'

XCode: Can't install software because it's not currently available on your computer

http://monicao.s3.amazonaws.com/gist_images/Screen%20Shot%202014-07-01%20at%2012.37.08%20PM.png

You probably have XCode 5.1.1 or higher and tried to install the command line tools via command line. See Install the command line developer tools section above.

Help Improve this

I wrote this down from memory. If any of the steps here don't work, please fork this gist, fix the issue and share with the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment