プロジェクト

全般

プロフィール

InstallRailsWindows » 履歴 » バージョン 74

Yuumi Yoshida, 2013-06-26 00:31

1 69 Yuumi Yoshida
h1.  Ruby on Rails 開発環境の作り方(Windows 7)
2 1 Yuumi Yoshida
3 74 Yuumi Yoshida
_2013/06/26更新_
4 1 Yuumi Yoshida
5
h2. WindowsPCの仕様
6 41 Yuumi Yoshida
7
* メモリー : 1Gbyte以上
8 51 Yuumi Yoshida
* ディスク空き容量: 500Mbyte以上
9 41 Yuumi Yoshida
* CPUの性能: 制限はありませんが、ここ3年以内に作られたPCが望ましい
10 69 Yuumi Yoshida
* OS: Windows 7
11 1 Yuumi Yoshida
12 41 Yuumi Yoshida
h2. インストール
13 25 Yuumi Yoshida
14 1 Yuumi Yoshida
15 25 Yuumi Yoshida
h3. 1. Ruby
16 52 Yuumi Yoshida
17 25 Yuumi Yoshida
18 69 Yuumi Yoshida
http://rubyinstaller.org/ のDownload ページから  *Ruby 2.0.0p195* をダウンロドし、実行して下さい。
19 25 Yuumi Yoshida
20 57 Yuumi Yoshida
# 最初の画面でライセンスに同意(I accept the License)
21 51 Yuumi Yoshida
# 次の画面でインストル先とオプションを選択します。
22 69 Yuumi Yoshida
** インストル先は C:\Ruby200 や D:\Ruby200 にして下さい。
23 51 Yuumi Yoshida
** Add Ruby excutables to your PATH をチェックして下さい
24 1 Yuumi Yoshida
!rubyInstaller.png!
25
# Installボタンを押す
26 52 Yuumi Yoshida
27
h3. 2.  DEVELOPMENT KIT
28 1 Yuumi Yoshida
29
OSに依存したライブラリーをWindows環境にインストールする為のツールもインストールします
30
31 69 Yuumi Yoshida
http://rubyinstaller.org/ のDownload ページから *DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe* をダウンロドし、実行して下さい。
32 1 Yuumi Yoshida
33 69 Yuumi Yoshida
ファイルを展開するディレクトリーを入力するダイアログが表示されるので、1.で指定したRubyのインストール先に DevKitディレクトリーを作成し (例 C:\Ruby200\DevKit) を指定して下さい。
34 1 Yuumi Yoshida
35
36
h3. 3. Rubyの確認とDEVELOPMENT KITのインストール作業
37
38
コマンドプロンプトを起動し ruby -v を実行し、以下のように表示されればOKです。
39
<pre>
40 52 Yuumi Yoshida
C:\>ruby -v
41 69 Yuumi Yoshida
ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
42 1 Yuumi Yoshida
</pre>
43
44
次に、DEVELOPMENT KITのインストール作業をコマンドプロンプトで行います。
45
<pre>
46 69 Yuumi Yoshida
C:\> cd \Ruby200\DevKit
47
48
C:\Ruby200\DevKit> ruby dk.rb init  
49
[INFO] found RubyInstaller v2.0.0 at C:/Ruby200
50 52 Yuumi Yoshida
  .....
51 1 Yuumi Yoshida
52 69 Yuumi Yoshida
C:\Ruby200\DevKit> ruby dk.rb install
53
[INFO] Installing 'C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/defaults/operating_system.rb'
54
  .....
55 1 Yuumi Yoshida
56 69 Yuumi Yoshida
</pre>
57 1 Yuumi Yoshida
58
59 69 Yuumi Yoshida
h3. 4. Ruby on Rails のインストール
60 1 Yuumi Yoshida
61 69 Yuumi Yoshida
引き続きコマンドプロンプトで、gemコマンドの更新を行います。
62 1 Yuumi Yoshida
次に Ruby on Railsをインストールします。 ある程度時間がかかります。
63
64
<pre>
65 69 Yuumi Yoshida
C:\> gem update --system -N
66 1 Yuumi Yoshida
  ...
67
68 69 Yuumi Yoshida
C:\> gem install bundler -N
69
  ...
70 1 Yuumi Yoshida
71 71 Yuumi Yoshida
C:\> gem install rspec -N
72
  ...
73
74 73 Yuumi Yoshida
C:\>gem install rails --version 4.0.0 -N
75 69 Yuumi Yoshida
  ....
76
77
</pre>
78
79 52 Yuumi Yoshida
Ruby on Rails の確認、以下のように表示されればOKです。
80 1 Yuumi Yoshida
<pre>
81 69 Yuumi Yoshida
C:\> rails -v
82
Rails 4.0.0.rc1
83 2 Yuumi Yoshida
</pre>
84 33 Yuumi Yoshida
85 72 Yuumi Yoshida
h3. 5. 関連ライブラリーのインストール
86 1 Yuumi Yoshida
87 72 Yuumi Yoshida
Ruby on Railsでは初めてプロジェクトを作った際に関連するライブラリーがインストールされるので、一度ダミーのプロジェクトを作成します。
88
89
<pre>
90
C:\> cd C:\temp
91
C:\temp> rails new dummy
92
C:\temp> cd dummy
93
</pre>
94
95
ただし、動作しないsqlite3ライブラリーがインストールされてしまうので削除します。
96
97
<pre>
98
C:\temp\dummy> gem uninstall sqlite3
99
</pre>
100
101
削除出来たら、ダミーのプロジェクトは削除してしまってかまいません。
102
103
<pre>
104
C:\temp\dummy> cd ..
105
C:\temp> rd /s /q dummy
106
107
</pre>
108
109
110
h3. 6. sqlite3ライブラリーのインストール
111 52 Yuumi Yoshida
112 69 Yuumi Yoshida
データベースライブラリー sqlite3は、そのままではインストールできないので以下のようにインストールします。
113 1 Yuumi Yoshida
114 69 Yuumi Yoshida
# C:\temp ディレクトリーを作成し、 そこに http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma をダウンロードします。
115
# 以下の手順でインストール
116
<pre> 
117
C:\> cd C:\temp
118
C:\temp> C:\Ruby200\DevKit\mingw\bin\bsdtar.exe -xvf sqlite-3.7.15.2-x86-windows.tar.lzma
119
C:\temp> copy bin\sqlite3.exe c:\Ruby200\bin
120 70 Yuumi Yoshida
C:\temp> gem install sqlite3 -N --platform=ruby -- --with-opt-dir=C:\temp
121 69 Yuumi Yoshida
</pre> 
122 55 Yuumi Yoshida
123 69 Yuumi Yoshida
* エラーなく終了すれば、C:\temp ディレクトリーは削除してかまいません。 
124
* 参照情報 参考  http://www.ruby-forum.com/topic/4413168
125 53 Yuumi Yoshida
126
127
128 69 Yuumi Yoshida
h3. A-1. Railsプロジェクトの作成時の注意
129 1 Yuumi Yoshida
130 69 Yuumi Yoshida
通常の rails new コマンドで Railsプロジェクトの作成すると、動作しないsqlite3ライブラリーがインストールされてしまいますので、以下の手順で作成して下さい。
131 59 Yuumi Yoshida
132 69 Yuumi Yoshida
<pre>
133
C:\Works> rails new todo_app -B
134
C:\Works> cd todo_app
135
C:\Works\todo_app> bundle install --local
136
</pre>
137 59 Yuumi Yoshida
138 69 Yuumi Yoshida
* 通常の rails new コマンドでプロジェクトを作成してしっまった場合は以下のように sqlite3-1.3.7-x86-mingw32 をアンインストールすればOKです
139 55 Yuumi Yoshida
140 69 Yuumi Yoshida
<pre>
141
C:\Works\todo_app> gem uninstall sqlite3
142 53 Yuumi Yoshida
143 69 Yuumi Yoshida
Select gem to uninstall:
144
 1. sqlite3-1.3.7-x86-mingw32
145
 2. sqlite3-1.3.7
146
 3. All versions
147
> 1
148
Successfully uninstalled sqlite3-1.3.7-x86-mingw32
149
</pre>
150 24 Yuumi Yoshida
151 69 Yuumi Yoshida
h3. A-2. 多数の PCにインストールする場合、
152 1 Yuumi Yoshida
153 69 Yuumi Yoshida
1台で上の作業を行った後、C:\Ruby200  ディレクトリーを他のPCにコピーし、環境変数 Path に C:\Ruby200\bin を追加すれば、他のPCでもRuby on Rails使えるようになります。