Mac OS X 10.8.2 + Homebrew + Git + rbenv + Ruby + Rails + Heroku

# Xcode(Command Line Tools)

* [Downloads](https://developer.apple.com/downloads/index.action#)
  * Command Line Tools (OS X Mountain Lion) for Xcode - November 2012

----

# Homebrew

* [Homebrew — MacPorts driving you to drink? Try Homebrew!](http://mxcl.github.com/homebrew/)
* [Homebrewの導入と使い方 | CAPH TECH](http://tech.caph.jp/2011/04/06/homebrew%E3%81%AE%E5%B0%8E%E5%85%A5%E3%81%A8%E4%BD%BF%E3%81%84%E6%96%B9/)

### Install Homebrew

```
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
----------
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press ENTER to continue or any other key to abort
★ENTER
==> /usr/bin/sudo /bin/mkdir /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:★パスワード
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> Downloading and Installing Homebrew...
Warning: Install the "Command Line Tools for Xcode": http://connect.apple.com
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
----------
```

----

# Git

```
brew install git
----------
==> Downloading http://git-core.googlecode.com/files/git-1.8.0.2.tar.gz
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/git/1.8.0.2 CC=cc CFLAGS= LDFLAGS= install
==> make CC=cc CFLAGS= LDFLAGS=
==> make clean
==> make CC=cc CFLAGS= LDFLAGS=
==> Downloading http://git-core.googlecode.com/files/git-manpages-1.8.0.2.tar.gz
######################################################################## 100.0%
==> Downloading http://git-core.googlecode.com/files/git-htmldocs-1.8.0.2.tar.gz
######################################################################## 100.0%
==> Caveats
The OS X keychain credential helper has been installed to:
  /usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
  /usr/local/share/git-core/contrib
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/git/1.8.0.2: 1252 files, 24M, built in 35 seconds
----------
```

```
git --version
----------
git version 1.7.10.2 (Apple Git-33)
----------
```

### SSHキー生成

* [Generating SSH Keys · github:help](https://help.github.com/articles/generating-ssh-keys)
* [SSH-KEYGEN (1)](http://www.unixuser.org/~euske/doc/openssh/jman/ssh-keygen.html)

```
cd ~/.ssh
```

```
ssh-keygen -t rsa
----------
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/shu/.ssh/id_rsa): ★Enter(キー作成パス)
Enter passphrase (empty for no passphrase): ★パスワード
Enter same passphrase again: ★パスワード再入力
Your identification has been saved in /Users/shu/.ssh/id_rsa.
Your public key has been saved in /Users/shu/.ssh/id_rsa.pub.
The key fingerprint is:
47:95:51:c4:28:3f:6f:32:7b:e9:fb:27:83:db:de:5f s.matsumoto0115@gmail.com
The key's randomart image is:
----------
```

```
ls
----------
id_rsa		id_rsa.pub	known_hosts
----------
```

* クリップボードへコピー(GitHubに登録)

```
pbcopy < ~/.ssh/id_rsa.pub
```

[SSH Keys](https://github.com/settings/ssh)
 => Add SSH key => Title／Key入力 => Add key => GitHubパスワードを入力

* アクセステスト

```
ssh -T git@github.com
----------
Identity added: /Users/shu/.ssh/id_rsa (/Users/shu/.ssh/id_rsa)
Hi shu0115! You've successfully authenticated, but GitHub does not provide shell access.
----------
```

----

# rbenv

* [sstephenson/rbenv · GitHub](https://github.com/sstephenson/rbenv)
* [OS X で rbenv を使って ruby 1.9.3 の環境を作る #Ruby #開発環境 #AdventCalendar - Qiita](http://qiita.com/items/9dd797f42e7bea674705)

### 各種ライブラリインストール

* openssl

```
brew install openssl
----------
==> Downloading http://openssl.org/source/openssl-1.0.1c.tar.gz
######################################################################## 100.0%
==> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1c --openssldir=/usr/local/etc/openssl zlib-dynamic shared d
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1c/share/man MANSUFFIX=ssl
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
/usr/local/Cellar/openssl/1.0.1c: 429 files, 15M, built in 3.0 minutes
----------
```

```
brew link openssl
----------
Linking /usr/local/Cellar/openssl/1.0.1c... 1139 symlinks created
----------
```

* readline

```
brew install readline
----------
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.4 --mandir=/usr/local/Cellar/readline/6.2.4/share/man --infodir=
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
/usr/local/Cellar/readline/6.2.4: 31 files, 1.6M, built in 16 seconds
----------
```

```
brew link readline
----------
Linking /usr/local/Cellar/readline/6.2.4... 12 symlinks created
----------
```

* libyaml

```
brew install libyaml
----------
==> Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/libyaml/0.1.4
==> make install
/usr/local/Cellar/libyaml/0.1.4: 7 files, 336K, built in 11 seconds
----------
```

### 2.2 Homebrew on Mac OS X(rbenvインストール)

```
brew update
----------
Initialized empty Git repository in /usr/local/.git/
remote: Counting objects: 90553, done.
remote: Compressing objects: 100% (41902/41902), done.
remote: Total 90553 (delta 63141), reused 72532 (delta 47795)
Receiving objects: 100% (90553/90553), 13.10 MiB | 1.28 MiB/s, done.
Resolving deltas: 100% (63141/63141), done.
From https://github.com/mxcl/homebrew
 * [new branch]      gh-pages   -> origin/gh-pages
 * [new branch]      go         -> origin/go
 * [new branch]      master     -> origin/master
 * [new branch]      superwip   -> origin/superwip
HEAD is now at fe80973 Fix stupid typo in bottle fix.
Already up-to-date.
----------
```

```
brew install rbenv
----------
==> Downloading https://github.com/sstephenson/rbenv/tarball/v0.3.0
######################################################################## 100.0%
Warning: The cleaning step did not complete successfully
Still, the installation was successful, so we will link it into your prefix
==> Caveats
To enable shims and autocompletion add to your profile:
  if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

To use Homebrew's directories rather than ~/.rbenv add to your profile:
  export RBENV_ROOT=/usr/local/opt/rbenv
==> Summary
/usr/local/Cellar/rbenv/0.3.0: 32 files, 168K, built in 3 seconds
----------
```

```
brew install ruby-build
----------
==> Downloading https://github.com/sstephenson/ruby-build/tarball/v20121204
######################################################################## 100.0%
==> ./install.sh
/usr/local/Cellar/ruby-build/20121204: 60 files, 264K, built in 3 seconds
----------
```

```
vi ~/.bash_profile
----------
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
----------
```

----

# Ruby

* インストール可能バージョンリスト

```
rbenv install -l
```

* インストール

```
rbenv install 1.9.3-p327
----------
Downloading yaml-0.1.4.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /Users/shu/.rbenv/versions/1.9.3-p327

Downloading ruby-1.9.3-p327.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/96118e856b502b5d7b3a4398e6c6e98c
Installing ruby-1.9.3-p327...
Installed ruby-1.9.3-p327 to /Users/shu/.rbenv/versions/1.9.3-p327
----------
```

* 使用バージョン設定

```
rbenv rehash
rbenv global 1.9.3-p327
ruby -v
----------
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.1]
----------
```

----

# Rails

```
vi ~/.gemrc
----------
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
----------
```

```
gem i rails
```

```
vi ~/.railsrc
----------
--skip-bundle
--skip-test-unit
----------
```

----

# Heroku Toolbelt

インストール: [Heroku Toolbelt](https://toolbelt.heroku.com/)

```
cat ~/.bash_profile
----------
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
----------
```

* Login

```
heroku login
----------
Enter your Heroku credentials.
Email: ★メールアドレス
Password (typing will be hidden): ★パスワード
Authentication successful.
----------
```

* Key Add

```
heroku keys:add ~/.ssh/id_rsa.pub
----------
Uploading SSH public key /Users/shu/.ssh/id_rsa.pub... done
----------
```

### Git設定／エイリアス

```
vi ~/.gitconfig
----------
[color]
	ui = auto
[alias]
	st = "status -sb"
	br = branch
	co = checkout
	ad = add
	cm = commit
	mg = merge
	ft = fetch
	df = diff
	pl = pull
	ph = push
	lg = log
	sw = show
	gr = "grep -n"
	sh = stash
	rt = remote
	cn = config
	rb = rebase
	cf = config
	cl = clone
	lgg = log --graph --date=short --decorate=short --pretty=format:'%Cgreen%h %Creset%cd %Cblue%cn %Cred%d %Creset%s'
	dff = diff --name-only
	dfw = diff --word-diff
	stsb = status -sb
	rs = reset
	bl = blame
	adp = add -p
	chp = cherry-pick
	rsall = reset --hard HEAD
[pull]
	rebase = true
----------
```

### 設定確認

```
git config -l
```

----

# Sublime Text 2

* [Sublime Text - Download](http://www.sublimetext.com/2)

### sublime-snippet

* [shu0115/sublime-snippet · GitHub](https://github.com/shu0115/sublime-snippet)

```
cd /Users/shu/Library/Application\ Support/Sublime\ Text\ 2/Packages/User
g cl git@github.com:shu0115/sublime-snippet.git
----------
Cloning into 'sublime-snippet'...
remote: Counting objects: 565, done.
remote: Compressing objects: 100% (200/200), done.
remote: Total 565 (delta 412), reused 508 (delta 355)
Receiving objects: 100% (565/565), 47.51 KiB, done.
Resolving deltas: 100% (412/412), done.
----------
```

```
cd sublime-snippet
```