プロジェクト

全般

プロフィール

InstallRailsMac » 履歴 » バージョン 69

Yuumi Yoshida, 2014-05-10 18:52

1 52 Yuumi Yoshida
h1.  Ruby on Rails 開発環境の作り方(Mac OS X 10.9)
2 1 Yuumi Yoshida
3 65 Yuumi Yoshida
_2014/05/10更新_
4 1 Yuumi Yoshida
5 46 Yuumi Yoshida
h3. 1 .  Command Line Toolsのインストール
6 1 Yuumi Yoshida
7 47 Yuumi Yoshida
ターミナルで以下を実行
8
<pre>
9 55 Yuumi Yoshida
$ gcc
10 47 Yuumi Yoshida
</pre>
11 1 Yuumi Yoshida
12 47 Yuumi Yoshida
以下のようなダイアログが表示されるので「インストール」をクリックするとダウンロード・インストールが開始します
13 34 Yuumi Yoshida
14 1 Yuumi Yoshida
!commandlinetools1.png!
15 49 Yuumi Yoshida
16
ダイアログが表示されずに、ターミナルに以下の様に表示された場合は gcc は既にインストールされています。
17
18
<pre>
19
clang: error: no input files
20
</pre>
21 47 Yuumi Yoshida
22 34 Yuumi Yoshida
h3. 2. homebrew(Unix系ツール)のインストール 
23 1 Yuumi Yoshida
24 46 Yuumi Yoshida
Hombrew ホームページ  http://brew.sh/
25 1 Yuumi Yoshida
26
ターミナルで以下を実行
27
28
<pre>
29 55 Yuumi Yoshida
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"  
30 46 Yuumi Yoshida
31
...
32
33 50 Yuumi Yoshida
Press ENTER to continue or any other key to abort       # ← enter(return)キーを押す
34 46 Yuumi Yoshida
35
...
36
37 50 Yuumi Yoshida
To proceed, enter your password, or type Ctrl-C to abort. 
38 46 Yuumi Yoshida
39 50 Yuumi Yoshida
Password:                    # ← ログインのパスワードを入力
40 46 Yuumi Yoshida
41 55 Yuumi Yoshida
$ brew doctor
42 46 Yuumi Yoshida
43
Your system is ready to brew.
44
                               
45 34 Yuumi Yoshida
</pre>
46
47 67 Yuumi Yoshida
h3. 3. rbenv, Rubyのインストール
48 34 Yuumi Yoshida
49
複数のバージョンのRubyを切り換えて使えるコマンドです  https://github.com/sstephenson/rbenv/
50
51 37 Yuumi Yoshida
ターミナルで以下を実行
52 1 Yuumi Yoshida
53 37 Yuumi Yoshida
* rbenv のインストール
54 27 Yuumi Yoshida
55 1 Yuumi Yoshida
<pre>
56 57 Yuumi Yoshida
$ brew update
57 55 Yuumi Yoshida
$ brew install openssl
58 1 Yuumi Yoshida
$ brew install readline
59 57 Yuumi Yoshida
$ brew install libyaml
60 55 Yuumi Yoshida
$ brew install ruby-build
61
$ brew install rbenv
62
$ rbenv install -l
63 47 Yuumi Yoshida
Available versions:
64
  1.8.6-p383
65
66
  ...
67
68 65 Yuumi Yoshida
   2.1.2     ←表示に2.1.2があることを確認する。
69 47 Yuumi Yoshida
70
   ...
71
72 61 Yuumi Yoshida
</pre>
73
74
* Rubyのインストール
75
* *以下のコマンドは長いの注意して下さい*
76 38 Yuumi Yoshida
77 37 Yuumi Yoshida
<pre>
78 65 Yuumi Yoshida
$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline) --with-openssl-dir=$(brew --prefix openssl) --with-yaml-dir=$(brew --prefix libyaml)" rbenv install 2.1.2
79 55 Yuumi Yoshida
$ rbenv rehash
80 65 Yuumi Yoshida
$ rbenv global 2.1.2
81 27 Yuumi Yoshida
</pre>
82 1 Yuumi Yoshida
83 34 Yuumi Yoshida
* .bash_profile  を編集、以下を追加
84
85
<pre>
86 18 Yuumi Yoshida
export PATH="$HOME/.rbenv/bin:$PATH" 
87 34 Yuumi Yoshida
eval "$(rbenv init -)" 
88
</pre>
89 1 Yuumi Yoshida
90 29 Yuumi Yoshida
* Rubyの確認、ターミナルで以下を実行
91 30 Yuumi Yoshida
92 34 Yuumi Yoshida
<pre>
93 55 Yuumi Yoshida
$ source .bash_profile
94
$ ruby -v
95 66 Yuumi Yoshida
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]  # ← 確認
96 1 Yuumi Yoshida
</pre>
97
98 37 Yuumi Yoshida
h3. 4 .Railsのインストール
99
100
ターミナルで以下を実行
101 32 Yuumi Yoshida
102 34 Yuumi Yoshida
* gemコマンドのアップデート
103 32 Yuumi Yoshida
104 34 Yuumi Yoshida
<pre>
105
$ gem update --system -N
106
</pre>
107
108 68 Yuumi Yoshida
@Latest version currently installed. Aborting.@ と表示された場合は、最新版がインストールされているので問題ありません。
109
110 34 Yuumi Yoshida
* インストール
111
112 55 Yuumi Yoshida
<pre>
113 1 Yuumi Yoshida
$ gem install bundler -N
114 61 Yuumi Yoshida
$ gem install rspec -v 3.0.0.beta2  -N
115 55 Yuumi Yoshida
$ gem install rails  -N
116 64 Yuumi Yoshida
$ rbenv rehash
117 1 Yuumi Yoshida
</pre>
118 34 Yuumi Yoshida
119 51 Yuumi Yoshida
※ gemインスト−ルの後の *rbenv rehash*  を忘れずに
120
121 34 Yuumi Yoshida
* 確認
122
123
<pre>
124 55 Yuumi Yoshida
$  rails -v
125 69 Yuumi Yoshida
Rails 4.1.1    # ← 確認
126 34 Yuumi Yoshida
</pre>
127 53 Yuumi Yoshida
128 54 Yuumi Yoshida
h3. 5. 関連ライブラリーのインストール
129
130
Ruby on Railsでは初めてプロジェクトを作った際に関連するライブラリーがインストールされるので、一度ダミーのプロジェクトを作成します。
131
132
<pre>
133 55 Yuumi Yoshida
$ cd /tmp
134
$ rails new dummy
135 54 Yuumi Yoshida
      create  
136
      create  README.rdoc
137
      create  Rakefile
138
139
      ...
140
141
Your bundle is complete!
142
Use `bundle show [gemname]` to see where a bundled gem is installed.
143
</pre>
144
145
ダミーのプロジェクトは削除してかまいません。
146
147 53 Yuumi Yoshida
h3. その他
148
149
エディターは Sublime text (ホームページ  http://www.sublimetext.com) がお勧めです。
150
(ただし Sublime textはフリーソフトではありません、無期限で試用できますが気に入ったら購入をお勧めします)
151
152
Sublime text をインストールしたら、ターミナルで以下を実行しすると、ターミナルからSublime textを起動でき便利になります。
153
154
<pre>
155 55 Yuumi Yoshida
$ ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
156 53 Yuumi Yoshida
157
subl .
158
</pre>