-
Notifications
You must be signed in to change notification settings - Fork 0
/
installing-rails-3-1.html
277 lines (275 loc) · 21.7 KB
/
installing-rails-3-1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Read This Before Installing Rails 3.1</title>
<link rel="stylesheet" href="/css/screen.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/css/gollum.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/css/syntax.css" type="text/css" charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.6.min.js" type="text/javascript"></script>
<script src="/javascript/jquery.text_selection-1.0.0.min.js" type="text/javascript"></script>
<script src="/javascript/jquery.previewable_comment_form.js" type="text/javascript"></script>
<script src="/javascript/jquery.tabs.js" type="text/javascript"></script>
<script src="/javascript/gollum.js" type="text/javascript"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-5109366-14']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="main">
<div class="site">
<div id="guides">
<div class="guide">
<div class="main">
<div class="actions">
<a href="http://railsapps.github.com/"><img src="http://railsapps.github.com/images/rails-36x36.jpg" title="Home" alt="Home"></a>
<a href="http://railsapps.github.com/">Rails Apps</a>
<a href="https://github.com/RailsApps">GitHub Repository</a>
</div><!-- class="actions" -->
<h1>Read This Before Installing Rails 3.1</h1>
<div class="content wikistyle gollum textile">
<h1>Read This Before Installing Rails 3.1</h1>
<p>Installing Rails 3.1: Detailed (and current) instructions on how to install Rails 3.1 with advice and troubleshooting tips.</p>
<p>This is a guide for developers using the starter apps from the <a href="http://railsapps.github.com/">Rails Apps</a> repository. Others may find it helpful as well.</p>
<p><a href="http://www.twitter.com/rails_apps"><img src="http://twitter-badges.s3.amazonaws.com/t_logo-a.png" title="Follow on Twitter" alt="Follow on Twitter" /></a> Follow <a href="http://twitter.com/rails_apps">@rails_apps</a> on Twitter for updates and timely Rails tips.</p>
<p>If you’re interested, see a discussion on Hacker News: <a href="http://news.ycombinator.com/item?id=2612611">Has installing Rails become too complex?</a>.</p>
<h2>What’s New</h2>
<p>You can read more about how the building blocks of the Rails platform work together by reading the article <a href="http://railsapps.github.com/managing-rails-versions-gems.html">Managing Rails Versions and Gems</a>. It explains the relationships among Ruby, RubyGems, Rails, Rake, Bundler, and gemfiles and offers some advice.</p>
<h4>Rails 3.1</h4>
<p>Rails 3.1.0 was released August 31, 2011. Eight release candidates were released beginning May 21, 2011. Rails 3.1 introduced the <a href="http://www.youtube.com/watch?v=cGdCI2HhfAU">asset pipeline</a> which enables proper organization of <span class="caps">CSS</span> and JavaScript. Other features include <a href="http://railscasts.com/episodes/266-http-streaming"><span class="caps">HTTP</span> streaming</a>, default jQuery, reversible migrations, mountable engines, identity map, prepared statements, Rack::Cache on by default, forced <span class="caps">SSL</span>, role-based mass-assignment protection, has_secure_password, and custom serializers. See the <a href="http://weblog.rubyonrails.org/2011/5/22/rails-3-1-release-candidate">Rails 3.1 release candidate announcement</a> for details. There’s a <a href="http://railscasts.com/episodes/265-rails-3-1-overview">Rails 3.1 Overview</a> from Ryan Bates and a <a href="https://gist.github.com/958283">changelog</a> for all the details. Yehuda Katz explains <a href="http://yehudakatz.com/2011/06/14/what-the-hell-is-happening-to-rails/">What’s Up With All These Changes in Rails?</a>. The best overview of Rails 3.1 is Michael Hartl’s <a href="http://ruby.railstutorial.org/chapters/rails-3-1#top">chapter on Rails 3.1</a> in his Ruby on Rails Tutorial book.</p>
<p><em>What You Need to Know:</em> The greatest impact for developers moving from Rails 3.0 to 3.1 is the new location for <span class="caps">CSS</span> and JavaScript files and changes to the application layout file. See the official <a href="http://guides.rubyonrails.org/asset_pipeline.html">Rails 3.1 Asset Pipeline guide</a> for details.</p>
<h4>Rake</h4>
<p>Rake is the build tool for Ruby. Rake version 0.9.0 was released May 20, 2011. Rake 0.8.7 installs as part of Ruby 1.9.2. Many gems depend on Rake and conflicting dependencies can be a problem, especially since the release of Rake version 0.9.0 . For an explanation, see <a href="http://blog.davidchelimsky.net/2011/05/28/rake-09-and-gem-version-constraints/">David Chelimsky’s blog post</a>. If needed, you can specify an earlier version of Rake in your gemfile to force the use of the Rake version specified in your gemfile. It’s good practice to use the command <code>bundle exec rake</code> instead of <code>rake</code> so you’ll use the version of Rake specified in your gemfile (or a dependency specified in the Gemfile.lock file) instead of the default version. For example, instead of <code>rake db:migrate</code>, run <code>bundle exec rake db:migrate</code>.</p>
<p><em>What You Need to Know:</em> Update Rake 0.8.7 to Rake 0.9.2 (or <a href="http://rubygems.org/gems/rake">newer</a>) with <code>gem update rake</code> before installing Rails 3.1. And use <code>bundle exec rake</code> instead of <code>rake</code>.</p>
<h4>RubyGems</h4>
<p>RubyGems is a package management framework for Ruby. RubyGems 1.8.10 was released August 27, 2011 and addresses a security vulnerability. With version 1.8.0 (released May 4, 2011), the RubyGems system gem began a series of rapid updates. Releases between 1.8.0 and 1.8.5 generated “noisy” deprecation warnings but most installed gems continued to work. RubyGems 1.8.5 eliminated most of the deprecation warnings. If you think a gem may be failing because of an incompatibility with the newest RubyGems implementation, you can troubleshoot by rolling back to an earlier RubyGems system gem with <code>gem update --system 1.7.2</code> or <code>gem update --system 1.3.7</code>.</p>
<p><em>What You Need to Know:</em> Use <code>gem update --system</code> to upgrade to the <a href="https://rubygems.org/gems/rubygems-update">newest RubyGems system gem</a>.</p>
<h2>Update or Install?</h2>
<p>If you already have Rails installed, you could run <code>gem update rails</code> for the newest version of Rails. In a word: <em>don’t</em>.</p>
<p>You’ll be better served by using rvm, the <a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a>, to create a new gemset for the new Rails version. Then you can switch back if necessary.</p>
<h2>Installing Rails 3.1</h2>
<p>Follow these instructions to set up Rails 3.1 as a platform for the <a href="http://railsapps.github.com/">Rails example apps</a> or any other apps you may build.</p>
<h4>Do You Ruby?</h4>
<p>Ruby should be installed on your computer. The version doesn’t matter; you’ll install Ruby 1.9.2 using rvm.</p>
<h4>Install or Update <span class="caps">RVM</span></h4>
<p>Use rvm, the <a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a>, to manage your Rails versions and create a gemset specifically for each application you build. If you encounter conflicting gem dependencies, you can isolate the errors by creating different gemsets with rvm.</p>
<p>The rvm website explains <a href="https://rvm.beginrescueend.com/rvm/install/">how to install rvm</a>.</p>
<p>If you already have rvm installed, update it to the latest version.</p>
<pre>
$ rvm get latest
$ rvm reload
$ rvm -v
</pre>
<h4>Install Ruby 1.9.2</h4>
<p>Check for the current <a href="http://www.ruby-lang.org/en/downloads/">recommended version of Ruby</a>. Ruby 1.9.2 patch level 290 was current when this was written.</p>
<p>If you don’t have it already, use rvm to install the recommended version of Ruby and make it your default:</p>
<pre>
$ rvm install ruby-1.9.2-p290
$ rvm --default use ruby-1.9.2-p290
$ ruby -v
</pre>
<h4>RubyGems</h4>
<p>The RubyGems package management system comes as part of a standard Ruby language installation.</p>
<p>What version of the RubyGems system is installed on your machine? Check with:</p>
<p>
<code>$ gem -v</code>
</p>
<p>Check for the <a href="https://rubygems.org/gems/rubygems-update">newest version of RubyGems</a>. It should be version 1.8.10 or newer (version 1.8.10 resolves a security vulnerability).</p>
<p>Use <code>gem update --system</code> to upgrade the RubyGems system.</p>
<p>See the article <a href="http://railsapps.github.com/managing-rails-versions-gems.html">Managing Rails Versions and Gems</a> if you have problems with gem incompatibilities.</p>
<h4>Create a Rails 3.1 Gemset</h4>
<p>Create a default Rails 3.1 gemset. It’s advisable to create a new gemset for each application you build. But to get started, create just one new Rails 3.1 gemset as your default.</p>
<pre>
$ rvm ruby-1.9.2-p290@rails31 --create --default
</pre>
<p>To see a list of the gemsets you have installed:</p>
<pre>
$ rvm gemset list
</pre>
<p>And see a list of the gems included with the standard Ruby installation:</p>
<pre>
$ gem list
</pre>
<h4>Update Rake</h4>
<p>Update from Rake 0.8.7 (installed with Ruby 1.9.2) to Rake 0.9.2 (or <a href="http://rubygems.org/gems/rake">newer</a>) before you install Rails 3.1.</p>
<pre>
$ gem update rake
$ rake --version
</pre>
<h4>Install Rails 3.1</h4>
<p>Now you can install Rails 3.1.</p>
<p>Check for the <a href="http://rubygems.org/gems/rails">current version of Rails</a>.</p>
<p>If you want the most recent stable release:</p>
<pre>
$ gem install rails
$ rails -v
</pre>
<p>If you want the newest beta version or release candidate, you can install with <code>--pre</code>.</p>
<pre>
$ gem install rails --pre
$ rails -v
</pre>
<p>Or you can get a specific version (sometimes the newest version is broken).</p>
<p>For example, if you want the Rails 3.1 final release, install with <code>--version=3.1.0</code>.</p>
<p>Or, as an alternative to <code>--pre</code>, for the newest available version:</p>
<pre>
$ gem install rails -v ">=3.1.0"
$ rails -v
</pre>
<h2>Generate a Rails App</h2>
<p>You can create a test application:</p>
<pre>
$ rails new testapp
</pre>
<p>Switch to the application root directory to examine and test what you’ve built.</p>
<pre>
$ cd testapp
</pre>
<h4>Ubuntu Linux</h4>
<p>For the Rails 3.1 release candidate, a JavaScript runtime is needed for Linux Ubuntu. It is not needed for Mac OS X or Windows. It will not be needed for the final release of Rails 3.1. Add this to your Gemfile:</p>
<pre>
gem 'therubyracer', '>= 0.8.2'
</pre>
<h4>Quick Test</h4>
<p>For a “smoke test” to see if everything runs, display a list of Rake tasks.</p>
<pre>
$ bundle exec rake -T
</pre>
<p>Remember, it’s good practice to run <code>bundle exec rake</code> instead of <code>rake</code> in case a gem specified in your gemfile (or a dependency in the Gemfile.lock file) relies on a version of Rake that’s different from the newest one you’ve installed.</p>
<h4>More Information</h4>
<p>See the <a href="http://guides.rubyonrails.org/getting_started.html">Rails Guides</a> for an introduction to building and running a Rails app.</p>
<p>See a list of <a href="http://railsapps.github.com/best-recommended-learning-rails-books-resources.html">Recommended Books and Online Resources for Learning Rails</a> if you’re just getting started.</p>
<h2>Get a Starter App</h2>
<p>The starter apps from the <a href="http://railsapps.github.com/">Rails Apps</a> repository provide good examples of Rails 3.1 apps.</p>
<p>Plus, by using one of these starter apps, you can minimize the effort needed to stay current with changing Rails and gem versions.</p>
<p>You can see an <a class="internal present" href="/rails-3-1-example-gemfile.html">Example Rails 3.1 Gemfile</a> from the starter apps.</p>
<h4>Starter Apps</h4>
<p>Each app provides a set of useful, popular Rails gems integrated into a working application. Each example is known to work and can serve as your personal “reference implementation”. Each is an open source project. Dozens of developers use the apps, report problems as they arise, and propose solutions as GitHub issues. There is a tutorial for each one so there’s no mystery code.</p>
<table>
<tr><th>Author </th>
<th>Starter App </th>
<th>Tutorial </th>
<th>App Template </th>
<th>Comments </th>
</tr>
<tr><td> Daniel Kehoe </td>
<td> <a href="https://github.com/RailsApps/rails3-devise-rspec-cucumber">Devise, RSpec, Cucumber</a> </td>
<td> <a href="https://github.com/RailsApps/rails3-devise-rspec-cucumber/wiki/Tutorial">Tutorial</a> </td>
<td> <a href="https://github.com/RailsApps/rails3-application-templates">App Template</a> </td>
<td> Uses Devise for authentication with ActiveRecord and SQLite for a database </td>
</tr>
<tr><td> Daniel Kehoe </td>
<td> <a href="https://github.com/RailsApps/rails3-mongoid-devise">Devise, Mongoid</a> </td>
<td> <a href="http://github.com/RailsApps/rails3-mongoid-devise/wiki/Tutorial">Tutorial</a> </td>
<td> <a href="https://github.com/RailsApps/rails3-application-templates">App Template</a> </td>
<td> Uses Devise for authentication with a MongoDB datastore </td>
</tr>
<tr><td> Daniel Kehoe </td>
<td> <a href="https://github.com/RailsApps/rails3-mongoid-omniauth">OmniAuth, Mongoid</a> </td>
<td> <a href="https://github.com/RailsApps/rails3-mongoid-omniauth/wiki/Tutorial">Tutorial</a> </td>
<td> <a href="https://github.com/RailsApps/rails3-application-templates">App Template</a> </td>
<td> Uses OmniAuth for authentication with a MongoDB datastore </td>
</tr>
</table><p>These starter apps were created with the <a href="https://github.com/RailsApps/rails_apps_composer">Rails Apps Composer</a> gem.</p>
<h4>Install from an Application Template</h4>
<p>You can use the files in the <a href="https://github.com/RailsApps/rails3-application-templates">Rails Application Templates</a> repository to build the starter apps.</p>
<p>Use the <code>"rails new app_name -m"</code> command to generate a Rails web application from a template.</p>
<p>You can add the <code>-T -O</code> flags to skip Test::Unit files and Active Record files.</p>
<h4>Rails 3 + Devise + RSpec + Cucumber</h4>
<p>To build the “rails3-devise-rspec-cucumber” starter application, run the command:</p>
<p>
<code>$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-devise-rspec-cucumber-template.rb -T</code>
</p>
<p>Use the <code>-T</code> flag to skip Test::Unit files.</p>
<p>See the <a href="https://github.com/RailsApps/rails3-devise-rspec-cucumber"><span class="caps">README</span></a> or <a href="https://github.com/RailsApps/rails3-devise-rspec-cucumber/wiki/Tutorial">tutorial</a> to learn how to configure and run the application.</p>
<h4>Rails 3 + Mongoid + Devise</h4>
<p>To build the “rails3-mongoid-devise” starter application, run the command:</p>
<p>
<code>$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-mongoid-devise-template.rb -T -O</code>
</p>
<p>Use the <code>-T -O</code> flags to skip Test::Unit files and Active Record files.</p>
<p>See the <a href="https://github.com/RailsApps/rails3-mongoid-devise"><span class="caps">README</span></a> or <a href="http://github.com/RailsApps/rails3-mongoid-devise/wiki/Tutorial">tutorial</a> to learn how to configure and run the application.</p>
<h4>Rails 3 + Mongoid + OmniAuth</h4>
<p>To build the “rails3-mongoid-omniauth” starter application, run the command:</p>
<p>
<code>$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-mongoid-omniauth-template.rb -T -O</code>
</p>
<p>Use the <code>-T -O</code> flags to skip Test::Unit files and Active Record files.</p>
<p>See the <a href="https://github.com/RailsApps/rails3-mongoid-omniauth"><span class="caps">README</span></a> or <a href="https://github.com/RailsApps/rails3-mongoid-omniauth/wiki/Tutorial">tutorial</a> to learn how to configure and run the application.</p>
<h2>Deploy to Heroku</h2>
<p>Heroku provides low cost, easily configured Rails application hosting. For your convenience, here are instructions for <a href="http://railsapps.github.com/rails-heroku-tutorial.html">Deploying to Heroku with Rails 3.1</a>.</p>
<h2>Using the .rvmrc file for Project-Specific Gemsets</h2>
<p>After you’ve created an rvm gemset that you’ll use for a project and begun to build the app, you can create an <strong>.rvmrc</strong> file in the application’s root directory. <span class="caps">RVM</span> recgonizes an <strong>.rvmrc</strong> file in a directory and loads the gemset specified inside.</p>
<p>Here’s how to create an <strong>.rvmrc</strong> file if you’re using a gemset named “ruby192@rails31”:</p>
<pre>
$ echo "rvm ruby192@rails31" > .rvmrc
</pre>
<p>Using an <strong>.rvmrc</strong> file means you’ll automatically be using the correct Rails and gem version when you run your application on your local machine. This works best if you create an rvm gemset specifically for your application.</p>
<h2>Troubleshooting</h2>
<p>Problems? Check the <a href="http://github.com/RailsApps/rails3-application-templates/issues">issues</a>.</p>
<h4>Problems with Rake</h4>
<p>If you see:</p>
<pre>
The template ... could not be loaded.
Error: You have already activated rake 0.8.7, but your Gemfile requires rake 0.9.x.
Consider using bundle exec.
</pre>
<p>You must update the standard Ruby installation from Rake 0.8.7 to Rake 0.9.2 (or <a href="http://rubygems.org/gems/rake">newer</a>) before using the application templates to generate a new Rails app.</p>
</div><!-- class="content" -->
<div class="comments">
<div class="content wikistyle gollum">
<h2>Comments</h2>
</div>
<p>Is this helpful? Please "like" below. Question or suggestion? Please add a comment below. Got a correction or addition? You can edit this page <a href="https://github.com/railsapps/railsapps.github.com/wiki/_pages">on the wiki</a> or create a <a href="https://github.com/RailsApps/railsapps.github.com/issues">GitHub issue</a> to alert me.</p>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'railsapps'; // required: replace example with your forum shortname
// The following are highly recommended additional parameters.
// var disqus_identifier = 'installing-rails-3-1.html';
// var disqus_url = 'http://railsapps.github.com/installing-rails-3-1.html';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div><!-- class="comments" -->
<br />
<br />
<div class="credits">
<div class="content wikistyle gollum">
<h2>Credits</h2>
</div>
<p>Daniel Kehoe (<a href="http://danielkehoe.com/">http://danielkehoe.com/</a>) initiated the project and wrote some examples and tutorials.</p>
<p>Your contributions are welcome!</p>
</div><!-- class="credits" -->
<div class="admin">
<small>Corrections? Additions? You can edit this page <a href="https://github.com/railsapps/railsapps.github.com/wiki/_pages">on the wiki</a>.</small>
<div style="float: right;">
<small>Last edited by <b>Daniel Kehoe</b>, 2011-09-01 12:24:10</small>
</div>
</div><!-- class="admin" -->
</div><!-- class="main" -->
</div><!-- class="guide" -->
</div><!-- id="guides" -->
</div><!-- class="site" -->
</div><!-- id="main" -->
<!-- MixPanel analytics -->
<script type='text/javascript'> var mp_protocol = (('https:' == document.location.protocol) ? 'https://' : 'http://'); document.write(unescape('%3Cscript src="' + mp_protocol + 'api.mixpanel.com/site_media/js/api/mixpanel.js" type="text/javascript"%3E%3C/script%3E')); </script> <script type='text/javascript'> try { var mpmetrics = new MixpanelLib('b1cf97418f8c5b129847e8a52edbae68'); } catch(err) { null_fn = function () {}; var mpmetrics = { track: null_fn, track_funnel: null_fn, register: null_fn, register_once: null_fn, register_funnel: null_fn }; } </script>
<!-- Clicky analytics -->
<script src="//static.getclicky.com/js" type="text/javascript"></script>
<script type="text/javascript">try{ clicky.init(66423523); }catch(e){}</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/66423523ns.gif" /></p></noscript>
</body>
</html>