Mac OS X 10.9.4(Mavericks) + Ruby 2.1.3 + Rails 4.1.6 + Heroku Toolbeltセットアップ


## インストール対象

* Xcode Command Line Tools
* Homebrew
* Git 2.1.2
* rbenv
* Ruby 2.1.3
* Rails 4.1.6
* Heroku Toolbelt

## Xcode Command Line Toolsインストール

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

## Homebrewインストール

* [Homebrew — OS X用パッケージマネージャー](http://brew.sh/index_ja.html)

```
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
----------
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /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
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 205759, done.
remote: Compressing objects: 100% (55352/55352), done.
remote: Total 205759 (delta 149221), reused 205759 (delta 149221)
Receiving objects: 100% (205759/205759), 43.70 MiB | 1014.00 KiB/s, done.
Resolving deltas: 100% (149221/149221), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 0bb2e41 gnu-cobol: put fails_with in stable block
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started
----------
```

## Gitインストール

```
brew install git
----------
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.1.2.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring git-2.1.2.mavericks.bottle.tar.gz
==> 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

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
?  /usr/local/Cellar/git/2.1.2: 1341 files, 32M
----------
```

### Gitパス修正

* 元々インストールされているGitを確認

```
git --version
----------
git version 1.9.3 (Apple Git-50)
----------
```

```
which git
----------
/usr/bin/git
----------
```

* HomebrewでインストールしたGitを確認

```
brew info git | grep stable
----------
git: stable 2.1.2 (bottled), HEAD
----------
```

```
/usr/local/bin/git --version
----------
git version 2.1.2
----------
```

* パス確認

```
echo $PATH
----------
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
----------
```

* パス修正

```
sudo vi /etc/paths
----------
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
----------
```

↓変更

```
/usr/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
```

※ターミナル再起動

* Git確認

```
git --version
----------
git version 2.1.2
----------
```

```
which git
----------
/usr/local/bin/git
----------
```

* brew診断

```
brew doctor
----------
Your system is ready to brew.
----------
```

## rbenvインストール

* [sstephenson/rbenv · GitHub](https://github.com/sstephenson/rbenv)
* [Setup Ruby On Rails on Mac OS X 10.9 Mavericks - GoRails](https://gorails.com/setup/osx/10.9-mavericks)

```
brew update
----------
Updated Homebrew from 0bb2e41e to 88b0e664.
==> Updated Formulae
libopendkim   subliminal
----------
```

```
brew install rbenv ruby-build
----------
==> Downloading https://github.com/sstephenson/rbenv/archive/v0.4.0.tar.gz
######################################################################## 100.0%
==> Caveats
To use Homebrew's directories rather than ~/.rbenv add to your profile:
  export RBENV_ROOT=/usr/local/var/rbenv

To enable shims and autocompletion add to your profile:
  if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
==> Summary
?  /usr/local/Cellar/rbenv/0.4.0: 31 files, 152K, built in 3 seconds
==> Installing dependencies for ruby-build: autoconf, pkg-config, openssl
==> Installing ruby-build dependency: autoconf
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/autoconf-2.69.mavericks.bottle.
######################################################################## 100.0%
==> Pouring autoconf-2.69.mavericks.bottle.1.tar.gz
?  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M
==> Installing ruby-build dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mavericks.bottl
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mavericks.bottle.2.tar.gz
?  /usr/local/Cellar/pkg-config/0.28: 10 files, 604K
==> Installing ruby-build dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1j.mavericks.bottle
######################################################################## 100.0%
==> Pouring openssl-1.0.1j.mavericks.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means 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.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

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.1j: 431 files, 15M
==> Installing ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20141016.tar.gz
######################################################################## 100.0%
==> ./install.sh
?  /usr/local/Cellar/ruby-build/20141016: 129 files, 552K, built in 2 seconds
----------
```

* .bash_profileに追記

```
vi ~/.bash_profile
----------
eval "$(rbenv init -)"
----------
```

```
echo $PATH
----------
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
----------
```

```
source ~/.bash_profile
```

```
echo $PATH
----------
/Users/USER_NAME/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
----------
```

## Rubyインストール

* インストール可能バージョンリスト
  * [オブジェクト指向スクリプト言語 Ruby](https://www.ruby-lang.org/ja/)

```
rbenv install -l
----------
  2.1.3
----------
```

* インストール

```
rbenv install 2.1.3
----------
Downloading ruby-2.1.3.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/0818beb7b10ce9a058cd21d85cfe1dcd233e98b7342d32e9a5d4bebe98347f01
Installing ruby-2.1.3...
Installed ruby-2.1.3 to /Users/USER_NAME/.rbenv/versions/2.1.3
----------
```

* 使用バージョン設定

```
ruby -v
----------
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
----------
```

```
rbenv global 2.1.3
```

```
ruby -v
----------
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
----------
```

## Railsインストール

```
gem i rails
```

```
rbenv rehash
```

```
rails -v
----------
Rails 4.1.6
----------
```

## Heroku Toolbeltインストール

[Heroku Toolbelt](https://toolbelt.heroku.com/) => 「Heroku Toolbelt for Mac OS X」

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

### Heroku Login

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

### Heroku Key Add

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