Skip to main content

Command Palette

Search for a command to run...

Setup Rails on Mountain Lion

Published
3 min read

A humble (*caught) guide for helping setup Rails environment on Mountain Lion with rbenv.

Install Xcode and it's friends...

First we need Xcode's Command Line Tools for install copies of the core command line tools and system headers into system folders.

If you don't need Xcode, you can download "Command Line Tools for Mountain Lion" from Apple developer site and install that, it's free but need an registed apple developer account. You can save about 4GB diskspace for doing so. Otherwise follow the steps below:

  1. Download and install Xcode from App Store first.

  2. Open Xcode, press Xcode -> preferences on the menu bar.

  3. Switch to Downloads -> Components section,

  4. install "Command Line Tools".


Install Homebrew

We choose Homebrew as our package manager, just like apt or yum for linux. After this step, you can use brew install something to install lots of useful tools, e.g., MySql, imagemagick and Node.js. Then we use Homebrew to install apple-gcc for compile ruby from the source, Git for up-to-date version control.

Open Terminal, paste this command beneath than Enter

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
```

Essential components

  • Execute each command followed:
brew install git
```
  • Optional
brew install mysql imagemagick

rbenv with Shell configs

Then we use rbenv and ruby-build for install multiple ruby version. But if you're kind of RVM's guy, just skip this section and go for it.

brew install rbenv ruby-build

After install the rbenv, we need to adjust our shell config to execute rbenv while system boot up.

  • In Terminal, execute each commands followed. (Note: if you're using ZSH, execute the ZSH part instead.)

BASH:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile && source ~/.bash_profile

ZSH:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init - zsh)"; fi' >> ~/.zshenv; source ~/.zshenv

Install Ruby

Whoa, the goal is just few steps far. Let's install all the ruby versions we need. Aren't we struggle all the way, just for that? Cross the fingers, guys.

  • In Terminal, execute each commands followed.
rbenv install 2.0.0-p247; rbenv rehash; rbenv global 2.0.0-p247
  • Optional: If you need Ruby Enterprise Edition, execute the commands followed.

Replace ; wich && in bash

Install Apple GCC

  • In Terminal, execute each commands followed.
sudo chown -R `whoami` /usr/local && brew update && brew tap homebrew/dupes && brew install apple-gcc42

If you need Ruby Enterprise Edition

CPPFLAGS=-I/opt/X11/include \
CC=/usr/local/bin/gcc-4.2 \
rbenv install ree-1.8.7-2012.02; rbenv rehash

Install important gems

Finally, it's done! Buy yourself a drink, you worth it! At the end let's install some gems and prepare for the party on Rails!

  • In Terminal, execute each commands followed.
gem install bundler rails

More from this blog

聊聊 Elixir 中的 type

最近有幾位朋友分別來問 Elixir 的 type 的問題,想說中文世界好像沒有比較完整的東西,就把知道的東西整理出來。 (目前) Elixir 的 type 能做什麼? tl;dr: 最主要是文件,然後在某種程度下防止錯誤。 我覺得這應該是在研究 Elixir 的 type 時最需要知道的事情了。不像 Haskell 及 F# 這種以型別著稱的 ML 系語言,Elixir / Erlang 本質上是個動態語言,所有與型別有關的標註都會被編譯器忽略。而 Erlang 內建的型別檢查工具 dia...

Oct 18, 20222 min read

Steam 上的程式教學類遊戲

農曆年期間比較有空,玩了一些之前買的遊戲。這次特別試了幾個標榜讓不會寫程式的人學寫程式的遊戲。分享一下試玩的心得。 1. 7 Billion Humans 考慮到劇情的話我最喜歡的是 7 Billion Humans。它用拖拉語法的方式下指令,一開始還蠻好上手的,但是因為只有 goto 那樣的結構,而操作的時候又是一次對所有的 worker 下指令,所以常常要想一下執行後每個人運作的順序。但是介面有正體中文,以「想要體驗一下寫程式大概是怎麼一回事」來說還蠻適合的。 2. while Tru...

Feb 24, 20201 min read

Let's (re)start from here.

最近的時間大半都花在這上面了。 算算應該是第五次弄部落格系統。算一下扣除上古時期用現成的之外,每個系統平均各寫六篇文章,也都撐不過兩年。前幾個分別用了 Refinery CMS -> jekyll -> middleman -> jekyll。想來架系統的總時數應該超過寫文章的時間 XD 而這次用上了 Gatsby + tailwindcss,除了恢復一下 GraphQL 的手感之外,這次還挑戰了不套別人做的版型,自己把類似上一個部落格的 style 刻出來。想說來分享一下這些技術的感想: G...

Jan 11, 20201 min read

Mostly Functional

31 posts

/.(ex|jsx?|rb|hs|rs|py)/, A father, a bookworm, a pluviophile. Co-organizer of http://Elixir.tw. Learning Satir, coaching & mediation.