How to set up The Wonderful World of Ruby and Rails™ on OS X.
Supported: 10.6 Snow Leopard and 10.7 Lion. Sorry, no 10.5 Leopard and so far not tested on 10.8 Mountain Lion.
Set up a Backup with Time Machine!!11! Yes, that might include going to the store and buying a harddrive. Do not continue without having a backup!
If you've never used the terminal before, find out how to write a tilde (
~) and do 5 minutes of shell basics.
Stack Overflow is the better Google for coding matters while DuckDuckGo doesn't track you, has the nicer UI and some nifty goodies. Tattoo "search the interwebs!!11!" on the back of your hands. Whenever you read a word you do not understand, look on the back of your hands!
1. Prepare and Install
Update to latest version of 10.6 Snow Leopard or 10.7 Lion.
You will find this at the Mac App Store. It's huge. This will take some time to download.
We also need the Command Line Tools for Xcode from within Xcode's Download preferences:
Make hidden files visible by pasting this into the terminal
$ defaults write com.apple.Finder AppleShowAllFiles YES
and restart the finder:
Then activate keyboard control for system dialogues:
is currently installed by doing:
$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
$ brew doctor
should happily announce that:
Your system is raring to brew.
Homebrew installs packages into
/usr/local/bin, so we need to edit the file
/etc/pathsto tell the system to look there first. Open
/etc/pathswith Sublime Text. On a fresh Lion install that file should look something like this:
/usr/bin /bin /usr/sbin /sbin /usr/local/bin
That last line
/usr/local/binneeds to go to the top, so the file looks like this:
/usr/local/bin /usr/bin /bin /usr/sbin /sbin
Save the file (will ask for your admin password) and restart the terminal.
We want to uninstall the git version that came with OS X and install an up-to-do version with homebrew:
$ which git
will output (on Lion at least)
so we need to do
$ sudo rm -rf /usr/bin/git
to remove the old git and
$ brew install git
to install the new version. Now you can do
$ git --version
$ which git
$ brew install rbenv $ brew install ruby-build
We now need to edit the bash profile which doesn't exist on a fresh system. Do:
$ touch ~/.bash_profile
paste the line
eval "$(rbenv init -)"
into it and restart the terminal.
$ rbenv versions
shows nothing. We need to install a Ruby into rbenv by doing:
$ rbenv install 1.9.3-p194
This may take a while. Then do:
$ rbenv versions
which should output:
$ rbenv global 1.9.3-p194 $ rbenv versions $ rbenv version
$ gem install bundler
and restart the terminal. Note: if you get a permission error, you must do
sudo gem install bundler–– same with other gems.
$ gem install heroku
and restart the terminal. Then do:
$ heroku login
2. Fork and deploy a test app
- create a folder called
- log into github
- go to https://github.com/5v3n/karathy
fork and clone it into
install needed gems with bundler:
$ cd ~/projects/my_awesome_blog $ bundle install
$ heroku create
push your app online:
$ git push heroku master
Open the URL in your browser.
Do you see your new blog? Congratulations #1!
3. Run the app locally on your machine
You don't have to push every change to Heroku to check it out. You can run a server on your very own machine.
$ gem install thin
and restart the terminal.
go to your blog directory and start the server:
$ cd ~/projects/my_awesome_blog $ thin start
0.0.0.0:3000in your webbrowser
Do you see your local copy of the blog? Congratulations #2!
4. Mod it
- Open the file
~/projects/my_awesome_blog/templates/layout.rhtmlin your code editor
- Find line 23
- Change "My Blog" to "Hello World"
- Save the file
- Check it out by updating your browser!
Do you see your changes? Congratulations #3!
Have a look at the terminal window where you started thin. You can see the requests your local server is answering.
Now commit and push:
$ git commit -am "Effyeah, my first commit evah!" $ git push heroku master $ git push origin master
Do you see your changes on your deployed version of the blog and on your github repo? Congratulations #4!
You did it! Now take a break,…
…get a beer and pat yourself on the back for next couple hours.
- sass user variables: tabs, word wrap, file types
- Look up
.gemrcand why it could make sense to add the line
gem: --no-rdoc --no-rito it
- bash_profile + links profile vs rc etc…
- Learn HAML and SASS
- Learn more shell
- Learn more Ruby
- Start blogging (you now have your own blog, you know?)
- Take a long walk (always helps)
- Do lots of reading about the tools you are using
- Find your local Ruby usergroup or Railsgirls group. If there is none, start one!
- Find the nearest BarCamp on Ruby and Rails. If there is none, start one!
- Check out out how to map your new blog to your own domain
- Drink more water
- Make a branch of your blog, change the design, later merge it to your master branch
- Try to get a rails app running
- Try Pow
- get more good advice…
- …and give feedback.
HT to Ben for the hint on enabling keybard control for all system dialogues.
Further reading and links
- Git, Git, Git and Git. Really, you can never know enough about Git, Git, Git and Git.
- How do RVM and RBENV actually work?
(more coming. maybe.)