So you just got your shiny new macbook and you're ready to get back to work. Here's how you get it all setup the standard way to be running rails.
The whole process usually takes around 30 minutes (most of the time is ruby compiling). It's very important you run these steps in order! Some steps will look like they succeeded if they are run out of order, but in fact will fail (like installing the pg gem before you've installed postgres. You've been warned!
Home brew can be installed by running the one liner at the bottom of the homebrew site.
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
Some kids at school may have told you about macports. Ignore them (at least for now) and just use homebrew. Its newer and more maintained. You can install them side by side later.
After this, in order to install anything, you're going to need the OSX command line tools. They don't ship with OS X for licensing reasons, but they are easy enough to get. Choose one of the following options.
Download the most recent version of "Command Line Tools (OS X Mountain Lion) for xCode" from the apple developer site. You will need to make a free account.
Install the 4+ gb xCode from the app store. Open it and goto xCode > Preferences > Downloads. Install the "Command Line Tools".
The old way is osx-gcc-installer, which was the solution before Apple offered the command line tools separate from xCode. This is no longer necessary.
Now, test it out, run on the command line
brew install wget without sudo. If it doesn't work, you may need to run the following command to give your user account permissions to change /usr/local where brew installs all your new packages.
chown $USER /usr/local/bin
Test it out:
Whew! That was the hardest step. Let's do some easier stuff.
2. Git & Github
First, install git. Should be easy now that we have homebrew! If you already downloaded it from the git website, its ok, but this way its easier to upgrade.
brew install git
Now in order to push to github and to SSH into your servers, you're going to need some SSH keys. If you already have them on your old computer, just copy them over to ~/.ssh and make sure permissions are set (ssh will let you know if the permissions are wrong).
If you haven't set them up, follow this great github guide.
To test that it's all set up right, for one you should have id_rsa and id_rsa.pub files and be able to SSH to github.
~ $ ls -la ~/.ssh drwx------ 10 derek staff 340 Dec 12 12:48 . drwxr-xr-x+ 67 derek staff 2278 Dec 24 16:41 .. -rw-r--r-- 1 derek staff 412 Nov 12 22:32 authorized_keys -rw------- 1 derek staff 1024 Nov 27 14:38 config -rw------- 1 derek staff 1675 Jul 19 13:51 id_rsa -rw-r--r-- 1 derek staff 412 Jul 19 13:51 id_rsa.pub -rw-r--r-- 1 derek staff 10818 Nov 27 14:43 known_hosts ~ $ ssh -T firstname.lastname@example.org Hi ddgromit! You've successfully authenticated, but GitHub does not provide shell access.
You have to have installed GCC via the command line tools in step #1 by now. Otherwise, you will get errors when you try this. If you are using RBEnv (vs RVM) instead, that's totally cool, but follow some other guide for this step.
Run the command on the RVM homepage for "Install RVM with ruby":
curl -L https://get.rvm.io | bash -s stable --ruby
This should install RVM and then ruby without any errors. You should get something like this
~ $ rvm list rvm rubies =* ruby-1.9.3-p194 [ x86_64 ] # => - current # =* - current && default # * - default
Do not jump ahead and install any gems right now or try doing a bundle install on your project. The pg gem needs postgres to be installed first, and if you don't do it its really annoying to clean up the problem.
This is where brew really helps you out.
brew install postgres
Once that's done, follow the instructions for "if this is your first install". If you lost the instructions, you can get them back with "brew info postgres". Running these commands will make postgres start on boot so you never have to do it manually.
They should look like
# DONT ACTUALLY RUN THESE, your version numbers are probably different If this is your first install, automatically load on login with: mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Verify its running
~ $ ps aux | grep postgres derek 483 0.0 0.0 2439076 428 ?? Ss 10:31PM 0:05.37 postgres: stats collector process derek 482 0.0 0.0 2442984 980 ?? Ss 10:31PM 0:04.28 postgres: autovacuum launcher process derek 481 0.0 0.0 2442852 56 ?? Ss 10:31PM 0:05.44 postgres: wal writer process derek 480 0.0 0.0 2442852 144 ?? Ss 10:31PM 0:06.94 postgres: writer process derek 400 0.0 0.0 2442852 208 ?? S 10:31PM 0:01.38 /usr/local/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log derek 34378 0.0 0.0 2432768 604 s003 S+ 5:04PM 0:00.00 grep postgres
Now, this is a really important "gotcha" Mountain Lion comes with its own outdated version of psql. Verify this with "psql --version" which shows that its not 9.1.x. You need to hide these alternate binaries or change your PATH. I recommend you just run the curl command on this NextMarvel guide.
If you are successful, this perplexing error
~ $ psql psql: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
should turn into a user or database error like this
~ $ psql psql: FATAL: database "derek" does not exist
Finally, set your user account name up as a super user (or whatever users your rails app needs)
createuser --superuser $USER
5. Test it on your project!
cd myproject rvm gemset create myproject rvm gemset use myproject bundle install rake db:migrate rails s
If you run into any other problems along the way, let me know via comments or email.