-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstallrubyonrails-ubuntu.html
More file actions
489 lines (488 loc) · 38.2 KB
/
installrubyonrails-ubuntu.html
File metadata and controls
489 lines (488 loc) · 38.2 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!DOCTYPE html>
<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Install Ruby on Rails 5.2
· Ubuntu · RailsApps</title>
<meta name="viewport" content="width=device-width">
<link href="https://plus.google.com/117374718581973393536" rel="publisher">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/css/normalize.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/css/foundation.min.css">
<link rel="stylesheet" href="http://railsapps.github.io/css/railsapps.css" />
<link rel="stylesheet" href="http://railsapps.github.io/css/syntax.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<script type="text/javascript">
window.analytics=window.analytics||[],window.analytics.methods=["identify","group","track","page","pageview","alias","ready","on","once","off","trackLink","trackForm","trackClick","trackSubmit"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var key=window.analytics.methods[i];window.analytics[key]=window.analytics.factory(key)}window.analytics.load=function(t){if(!document.getElementById("analytics-js")){var a=document.createElement("script");a.type="text/javascript",a.id="analytics-js",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.io/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)}},window.analytics.SNIPPET_VERSION="2.0.9",
window.analytics.load("l1stqfqqbf");
window.analytics.page();
window.analytics.ready(function () {
ga('require', 'linker');
ga('linker:autoLink', ['railscomposer.com','learn-rails.com','blog.railsapps.org','tutorials.railsapps.org']);
});
</script>
</head>
<body>
<div class="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<a href="http://railsapps.github.io/" class="brand">RailsApps Project</a>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<ul class="right">
<li><a href="https://tutorials.railsapps.org/" class="google">Tutorials</a></li>
<li><a href="http://twitter.com/rails_apps" class="twitter">Twitter</a></li>
<li><a href="http://blog.railsapps.org/" class="twitter">Blog</a></li>
<li><a href="https://github.com/RailsApps" class="github">GitHub Repository</a></li>
</ul>
</section>
</nav>
</div>
<div class="row">
<div class="large-12 columns">
<div class="content wikistyle gollum textile">
<h1>Install Ruby on Rails · Ubuntu Linux</h1>
<h4>by Daniel Kehoe</h4>
<p><em>Last updated 6 December 2016</em></p>
<p>Install Ruby on Rails 5.2 on Ubuntu Linux. Up-to-date, detailed instructions for the Rails newest release. How to install Rails 5.2, the newest version of Rails, on Ubuntu.</p>
<p>This in-depth installation guide is used by developers to configure their working environment for real-world Rails development. This guide doesn’t cover installation of Ruby on Rails for a production server.</p>
<p>To develop with Rails on Ubuntu, you’ll need Ruby (an interpreter for the Ruby programming language) plus gems (software libraries) containing the Rails web application development framework.</p>
<p>For an overview of what’s changed in each Rails release, see a <a href="http://railsapps.github.io/rails-release-history.html">Ruby on Rails Release History</a>.</p>
<h4>If You Are New to Rails</h4>
<p>If you’re new to Rails, see <a href="http://railsapps.github.io/what-is-ruby-rails.html">What is Ruby on Rails?</a>, the book <a href="http://learn-rails.com/learn-ruby-on-rails.html">Learn Ruby on Rails</a>, and recommendations for a <a href="https://tutorials.railsapps.org/rails-tutorial">Rails tutorial</a>.</p>
<h4><a href="http://railsapps.github.io/"><img src="http://railsapps.github.io/images/join/join-railsapps.png" title="Join RailsApps" alt="Join RailsApps"></a></h4>
<h4>What is the RailsApps Project?</h4>
<p>This is an article from the RailsApps project. The <a href="http://railsapps.github.io/">RailsApps project</a> provides example applications that developers use as starter apps. Hundreds of developers use the apps, report problems as they arise, and propose solutions. Rails changes frequently; each application is known to work and serves as your personal “reference implementation.” Support for the project comes from subscribers. If this article is useful, please support us and <a href="http://railsapps.github.io/">join the RailsApps project</a>.</p>
<h2>Ruby on Rails on Ubuntu</h2>
<p>Ubuntu is a popular platform for Rails development, as are other Unix-based operating systems such as Mac OS X. Installation is relatively easy and widespread help is available in the Rails developer community.</p>
<h3>Use a Ruby Version Manager</h3>
<p>You’ll need an easy way to switch between Ruby versions. Just as important, you’ll have a dependency mess if you install gems into the system environment. I recommend <a href="https://rvm.io/"><span class="caps">RVM</span></a> to manage Ruby versions and gems because it is popular, well-supported, and full-featured. If you are an experienced Unix administrator, you can consider alternatives such as <a href="https://github.com/postmodern/chruby">Chruby</a> or Sam Stephenson’s <a href="https://github.com/sstephenson/rbenv">rbenv</a>.</p>
<p>Conveniently, you can use <span class="caps">RVM</span> to install Ruby.</p>
<h3>Don’t Install Ruby from a Package</h3>
<p>Ubuntu provides a package manager system for installing system software. You’ll use this to prepare your computer before installing Ruby. However, don’t use <code>apt-get</code> to install Ruby. The package manager will install an outdated version of Ruby. And it will install Ruby at the system level (for all users). It’s better to use <span class="caps">RVM</span> to install Ruby within your user environment.</p>
<h3>Hosted Development</h3>
<p>You can use Ruby on Rails without actually installing it on your computer. Hosted development, using a service such as <a href="https://c9.io/">Cloud9</a>, means you get a computer “in the cloud” that you use from your web browser. Any computer can access the hosted development environment, though you’ll need a broadband connection. Cloud9 is free for small projects.</p>
<p>Using a hosted environment means you are no longer dependent on the physical presence of a computer that stores all your files. If your computer crashes or is stolen, you can continue to use your hosted environment from any other computer. Likewise, if you frequently work on more than one computer, a hosted environment eliminates the difficulty of maintaining duplicate development environments. For these reasons some developers prefer to “work in the cloud” using Cloud9. Cloud9 is a good option if you have trouble installing Ruby on Rails on your computer.</p>
<h2>Prepare Your System</h2>
<p>You’ll need to prepare your computer with the required system software before installing Ruby on Rails.</p>
<p>You’ll need superuser (root) access to update the system software.</p>
<p>Update your package manager first:</p>
<pre>
$ sudo apt-get update
</pre>
<p>This must finish without error or the following step will fail.</p>
<p>Install <a href="http://en.wikipedia.org/wiki/CURL">Curl</a>:</p>
<pre>
$ sudo apt-get install curl
</pre>
<p>You’ll use Curl for installing <span class="caps">RVM</span>.</p>
<h2>Install Ruby Using <span class="caps">RVM</span>
</h2>
<p>Use <span class="caps">RVM</span>, the <a href="https://rvm.io/">Ruby Version Manager</a>, to install Ruby and manage your Rails versions.</p>
<p>If you have an older version of Ruby installed on your computer, there’s no need to remove it. <span class="caps">RVM</span> will leave your “system Ruby” untouched and use your shell to intercept any calls to Ruby. Any older Ruby versions will remain on your system and the <span class="caps">RVM</span> version will take precedence.</p>
<p>Ruby 2.4.2 was current when this was written. You can check for the current <a href="http://www.ruby-lang.org/en/downloads/">recommended version of Ruby</a>. <span class="caps">RVM</span> will install the newest stable Ruby version.</p>
<p>The <span class="caps">RVM</span> website explains <a href="https://rvm.io/rvm/install/">how to install <span class="caps">RVM</span></a>. Here’s the simplest way:</p>
<pre>
$ \curl -L https://get.rvm.io | bash -s stable --ruby
</pre>
<p>Note the backslash before “curl” (this avoids potential version conflicts).</p>
<p>The “—ruby” flag will install the newest version of Ruby.</p>
<p><span class="caps">RVM</span> includes an “autolibs” option to identify and install system software needed for your operating system. See the article <a href="https://blog.engineyard.com/2013/rvm-ruby-2-0"><span class="caps">RVM</span> Autolibs: Automatic Dependency Handling and Ruby 2.0</a> for more information.</p>
<h4>If You Already Have <span class="caps">RVM</span> Installed</h4>
<p>If you already have <span class="caps">RVM</span> installed, update it to the latest version and install Ruby:</p>
<pre>
$ rvm get stable --autolibs=enable
$ rvm install ruby
$ rvm --default use ruby-2.4.2
</pre>
<h4>Installation Troubleshooting and Advice</h4>
<h4>
<span class="caps">RVM</span> Troubleshooting</h4>
<p>If you have trouble installing Ruby with <span class="caps">RVM</span>, you can get help directly from the <span class="caps">RVM</span> team using the <span class="caps">IRC</span> (Internet Relay Chat) channel #rvm on irc.freenode.net:</p>
<p><a href="http://webchat.freenode.net/?channels=rvm">http://webchat.freenode.net/?channels=rvm</a></p>
<p>If you’ve never used <span class="caps">IRC</span>, it’s worthwhile to figure out how to use <span class="caps">IRC</span> because the <span class="caps">RVM</span> team is helpful and friendly. <span class="caps">IRC</span> on freenode requires registration (see <a href="http://en.wikipedia.org/wiki/Wikipedia:IRC/Tutorial#Nickname_registration">how to register</a>).</p>
<h2>Install Node.js</h2>
<p>Since Rails 3.1, a JavaScript runtime has been needed for development on Ubuntu Linux. The JavaScript runtime is required to compile code for the Rails asset pipeline. For development on Ubuntu Linux it is best to install the <a href="http://nodejs.org/">Node.js</a> server-side JavaScript environment.</p>
<pre>
$ sudo apt-get install nodejs
</pre>
<p>and set it in your <code>$PATH</code>.</p>
<p>If you don’t install Node.js, you’ll need to add this to the Gemfile for each Rails application you build:</p>
<pre>
gem 'therubyracer'
</pre>
<h2>Check the Gem Manager</h2>
<p><a href="https://rubygems.org/gems/rubygems-update">RubyGems</a> is the gem manager in Ruby.</p>
<p>Check the installed gem manager version. You may see:</p>
<pre>
$ gem -v
2.4.2
</pre>
<p>At the time this was written, a <a href="https://rubygems.org/gems/rubygems-update">newer RubyGems</a> version was available. Use <code>gem update --system</code> to upgrade the Ruby gem manager:</p>
<pre>
$ gem update --system
</pre>
<h2>
<span class="caps">RVM</span> Gemsets</h2>
<p>Not all Rails developers use <span class="caps">RVM</span> to manage gems, but many recommend it.</p>
<p>Display a list of gemsets:</p>
<pre>
$ rvm gemset list
gemsets for ruby-2.4.2
=> (default)
global
</pre>
<p>Only the “default” and “global” gemsets are pre-installed.</p>
<p>If you get an error “rvm is not a function,” close your console and open it again.</p>
<h2 id="gems">RVM’s Global Gemset</h2>
<p>See what gems are installed in the “global” gemset:</p>
<pre>
$ rvm gemset use global
$ gem list
</pre>
<p>A trouble-free development environment requires the newest versions of the default gems.</p>
<p>Several gems are installed with Ruby or the <span class="caps">RVM</span> default gemset:</p>
<ul>
<li><a href="http://rubygems.org/gems/bundler-unload">bundler-unload</a></li>
<li><a href="http://rubygems.org/gems/rake">rake</a></li>
<li><a href="http://rubygems.org/gems/rubygems-bundler">rubygems-bundler</a></li>
<li><a href="http://rubygems.org/gems/rvm">rvm</a></li>
</ul>
<p>To get a list of gems that are outdated:</p>
<pre>
$ gem outdated
### list not shown for brevity
</pre>
<p>To update all stale gems:</p>
<pre>
$ gem update
### list not shown for brevity
</pre>
<p>In particular, rake should be updated to version 10.2.1 or newer.</p>
<h4>Stay Current</h4>
<p>You can track updates to gems at the RubyGems.org site by creating an account and visiting your <a href="https://rubygems.org/dashboard">dashboard</a>. Search for each gem you use and “subscribe” to see a feed of updates in the dashboard (an <span class="caps">RSS</span> feed is available from the dashboard). After you’ve built an application and set up a GitHub repository, you can stay informed with <a href="https://gemnasium.com/">Gemnasium</a> or <a href="https://www.versioneye.com/">VersionEye</a>. These services survey your GitHub repo and send email notifications when gem versions change. Gemnasium and VersionEye are free for public repositories with a premium plan for private repositories.</p>
<h4>Faster Gem Installation</h4>
<p>By default, when you install gems, documentation files will be installed. Developers seldom use gem documentation files (they’ll browse the web instead). Installing gem documentation files takes time, so many developers like to toggle the default so no documentation is installed.</p>
<p>Here’s how to speed up gem installation by disabling the documentation step:</p>
<pre>
$ echo "gem: --no-document" >> ~/.gemrc
</pre>
<p>This adds the line <code>gem: --no-document</code> to the hidden <strong>.gemrc</strong> file in your home directory.</p>
<h4>Install Bundler</h4>
<p>The <a href="https://rubygems.org/gems/bundler">Bundler</a> gem is an essential tool for managing gems when developing and running Rails applications. <span class="caps">RVM</span> used to install Bundler automatically. As of version 1.26.11 (released March 31, 2015), <span class="caps">RVM</span> no longer installs Bundler automatically. You must install Bundler:</p>
<pre>
$ gem install bundler
</pre>
<h4>Nokogiri</h4>
<p><a href="http://nokogiri.org/">Nokogiri</a> is a gem that is a dependency for many other gems. Nokogiri is a gem that requires compilation for your specific operating system. As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri. However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).</p>
<p>To save time, install the Nokogiri gem in the <span class="caps">RVM</span> global gemset:</p>
<pre>
$ gem install nokogiri
</pre>
<p>During installation, Nokogiri will display two lengthy messages in the console. It will also pause without displaying any progress for as long as five minutes. Don’t assume installation has failed unless you see an error message or you’ve waited more than ten minutes.</p>
<p>If installation fails, make sure your system is configured properly (look for help on <a href="http://stackoverflow.com/questions/tagged/nokogiri">Stack Overflow</a>).</p>
<h2>Rails Installation Options</h2>
<p>Check for the <a href="http://rubygems.org/gems/rails">current version of Rails</a>. Rails 5.1 was current and Rails 5.2 was available in beta release when this was written.</p>
<p>You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into project-specific gemsets, so each project has the appropriate version of Rails.</p>
<p>If you install Rails at this point, you will install it into the global gemset.</p>
<p>I recommend to make a gemset for the beta release:</p>
<pre>
$ rvm use ruby-2.4.2@rails5.2 --create
</pre>
<p>Here are the options you have for installing Rails.</p>
<p>If you want the newest beta version or release candidate, you can install with <code>--pre</code>.</p>
<p>I recommend installing the beta release:</p>
<pre>
$ gem install rails --pre
</pre>
<p>If you want to install the current stable release:</p>
<pre>
$ gem install rails
</pre>
<p>Or you can get a specific version.</p>
<p>For example, if you want the Rails 3.2.18 release:</p>
<pre>
$ gem install rails --version=3.2.18
$ rails -v
</pre>
<h2>Create a Workspace Folder</h2>
<p>You’ll need a convenient folder to store your Rails projects. You can give it any name, such as <strong>code/</strong> or <strong>projects/</strong>. For this tutorial, we’ll call it <strong>workspace/</strong>.</p>
<p>Create a projects folder and move into the folder:</p>
<pre>
$ mkdir workspace
$ cd workspace
</pre>
<p>This is where you’ll create your Rails applications.</p>
<h2>New Rails Application</h2>
<p>Here’s how to create a project-specific gemset, installing Rails, and creating a new application.</p>
<pre>
$ mkdir myapp
$ cd myapp
$ rvm use ruby-2.4.2@myapp --ruby-version --create
$ gem install rails
$ rails new .
</pre>
<p>We’ll name the new application “myapp.” Obviously, you can give it any name you like.</p>
<p>With this workflow, you’ll first create a root directory for your application, then move into the new directory.</p>
<p>With one command you’ll create a new project-specific gemset. The option “—ruby-version” creates <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files in the root directory. <span class="caps">RVM</span> recognizes these files in an application’s root directory and loads the required version of Ruby and the correct gemset whenever you enter the directory.</p>
<p>When we create the gemset, it will be empty (though it inherits use of all the gems in the global gemset). We immediately install Rails. The command <code>gem install rails</code> installs the most recent release of Rails.</p>
<p>Finally we run <code>rails new .</code>. We use the Unix “dot” convention to refer to the current directory. This assigns the name of the directory to the new application.</p>
<p>This approach is different from the way most beginners are taught to create a Rails application. Most instructions suggest using <code>rails new myapp</code> to generate a new application and then enter the directory to begin work. Our approach makes it easy to create a project-specific gemset and install Rails before the application is created.</p>
<p>The <code>rails new</code> command generates the default Rails starter app. If you wish, you can use the <a href="http://railsapps.github.io/rails-composer/">Rails Composer</a> tool to generate a starter application with a choice of basic features and popular gems.</p>
<h4>Quick Test</h4>
<p>For a “smoke test” to see if everything runs, display a list of Rake tasks.</p>
<pre>
$ rake -T
</pre>
<p>There’s no need to run <code>bundle exec rake</code> instead of <code>rake</code> when you are using <span class="caps">RVM</span> (see <a href="https://rvm.io/integration/bundler/"><span class="caps">RVM</span> and bundler integration</a>).</p>
<p>This concludes the instructions for installing Ruby and Rails. Read on for additional advice and tips.</p>
<h2>Rails Starter Apps</h2>
<p>The starter application you create with <code>rails new</code> is very basic.</p>
<p>Use the <a href="http://railsapps.github.io/rails-composer/">Rails Composer</a> tool to build a full-featured Rails starter app.</p>
<p>You’ll get a choice of starter applications with basic features and popular gems.</p>
<p>Here’s how to generate a new Rails application using the Rails Composer tool:</p>
<p>Using the conventional approach:</p>
<pre>
$ rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
</pre>
<p>Or, first creating an empty application root directory:</p>
<pre>
$ mkdir myapp
$ cd myapp
$ rvm use ruby-2.4.2@myapp --ruby-version --create
$ gem install rails
$ rails new . -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
</pre>
<p>The <code>-m</code> option loads an application template that is hosted on GitHub.</p>
<p>You can add the <code>-T</code> flags to skip Test::Unit if you are using RSpec for testing.</p>
<p>You can add the <code>-O</code> flags to skip Active Record if you are using a NoSQL datastore such as MongoDB.</p>
<p>If you get an error “OpenSSL certificate verify failed” when you try to generate a new Rails app, see the article <a href="http://railsapps.github.io/openssl-certificate-verify-failed.html">OpenSSL errors and Rails</a>.</p>
<h4>Rails Tutorials and Example Applications</h4>
<p>The <a href="http://railsapps.github.io/">RailsApps project</a> provides example apps that show how real-world Rails applications are built. 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. Purchasing a <a href="https://tutorials.railsapps.org/">subscription for the tutorials</a> gives the project financial support.</p>
<table>
<tr>
<th>Example Applications for Rails </th>
<th>Tutorial </th>
<th>Comments </th>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/learn-rails">Learn Rails</a> </td>
<td> <a href="http://learn-rails.com/learn-ruby-on-rails.html">Learn Ruby on Rails</a> </td>
<td> introduction to Rails for beginners </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-bootstrap">Rails and Bootstrap</a> </td>
<td> <a href="http://railsapps.github.io/rails-bootstrap">Rails Bootstrap Tutorial</a> </td>
<td> starter app for Rails and Bootstrap </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-foundation">Rails and Foundation</a> </td>
<td> <a href="http://railsapps.github.io/rails-foundation">Rails Foundation Tutorial</a> </td>
<td> starter app for Rails and Zurb Foundation </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-mailinglist-activejob">Mailing List with Active Job</a> </td>
<td> <a href="http://railsapps.github.io/rails-mailinglist-activejob">Mailing List with Active Job Tutorial</a> </td>
<td> background processing </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-omniauth">OmniAuth and Rails</a> </td>
<td> <a href="http://railsapps.github.io/rails-omniauth/">OmniAuth Tutorial</a> </td>
<td> OmniAuth for authentication </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-devise">Devise and Rails</a> </td>
<td> <a href="http://railsapps.github.io/rails-devise">Devise Tutorial</a> </td>
<td> Devise for authentication </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-devise-role">Role-Based Authorization</a> </td>
<td> <a href="http://railsapps.github.io/rails-devise-roles">Role-Based Authorization Tutorial</a> </td>
<td> Simple authorization </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-devise-pundit">Pundit and Rails</a> </td>
<td> <a href="http://railsapps.github.io/rails-devise-pundit">Rails Pundit Tutorial</a> </td>
<td> Pundit for authorization </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-signup-download">Sign Up and Download</a> </td>
<td> <a href="http://railsapps.github.io/rails-signup-download">Sign Up and Download Tutorial</a> </td>
<td> Devise with authorization to download a <span class="caps">PDF</span> file </td>
</tr>
<tr>
<td> <a href="https://github.com/RailsApps/rails-stripe-checkout">Stripe Checkout</a> </td>
<td> <a href="http://railsapps.github.io/rails-stripe-checkout">Stripe Checkout Tutorial</a> </td>
<td> selling a product with Stripe Checkout </td>
</tr>
</table>
<h2>Adding a Gemset to an Existing Application</h2>
<p>If you’ve already created an application with the command <code>rails new myapp</code>, you can still create a project-specific gemset. Here’s how to create a gemset for an application named “myapp” and create <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files in the application’s root directory:</p>
<pre>
$ rvm use ruby-2.4.2@myapp --ruby-version --create
</pre>
<p>You’ll need to install Rails and the gems listed in your Gemfile into the new gemset by running:</p>
<pre>
$ gem install rails
$ bundle install
</pre>
<h3>Specifying a Gemset for an Existing Application</h3>
<p>If you have already created both an application and a gemset, but not <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files, here’s how to add the files. For example, if you want to use an existing gemset named “ruby-2.4.2@myapp”:</p>
<pre>
$ echo "ruby-2.4.2" > .ruby-version
$ echo "myapp" > .ruby-gemset
</pre>
<p>Using <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files means you’ll automatically be using the correct Rails and gem version when you switch to your application root directory on your local machine.</p>
<h2>Databases for Rails</h2>
<p>Rails uses the <a href="http://www.sqlite.org/">SQLite</a> database by default. <span class="caps">RVM</span> installs SQLite and there’s nothing to configure.</p>
<p>Though SQLite is adequate for development (and even some production applications), a new Rails application can be configured for other databases. The command <code>rails new myapp --database=</code> will show you a list of supported databases.</p>
<pre>
Supported for preconfiguration are: mysql, oracle, postgresql, sqlite3, frontbase, ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, jdbcpostgresql, jdbc.
</pre>
<p>For example, to create a new Rails application to use <a href="http://www.postgresql.org/">PostgreSQL</a>:</p>
<pre>
$ rails new myapp --database=postgresql
</pre>
<p>The <code>--database=postgresql</code> parameter will add the pg database adapter gem to the Gemfile and create a suitable config/database.yml file.</p>
<p>Don’t use the <code>--database=</code> argument with the Rails Composer tool. You’ll select a database from a menu instead.</p>
<h2>Deployment</h2>
<p>If you wish to run your own servers, you can deploy a Rails application using <a href="http://en.wikipedia.org/wiki/Capistrano">Capistrano</a> deployment scripts. However, unless system administration is a personal passion, it is much easier to deploy your application with a “platform as a service” provider such as Heroku.</p>
<h3>Hosting</h3>
<p>For easy deployment, use a “platform as a service” provider such as:</p>
<ul>
<li><a href="http://www.heroku.com/">Heroku</a></li>
<li><a href="http://www.cloudfoundry.com/">CloudFoundry</a></li>
<li><a href="http://www.engineyard.com/">EngineYard</a></li>
<li><a href="https://openshift.redhat.com/app/">OpenShift</a></li>
</ul>
<p>For deployment on Heroku, see the article:</p>
<ul>
<li><a href="http://railsapps.github.io/rails-heroku-tutorial.html">Rails on Heroku</a></li>
</ul>
<h2>Security</h2>
<p>By design, Rails encourages practices that avoid common web application vulnerabilities. The Rails security team actively investigates and patches vulnerabilities. If you use the most current version of Rails, you will be protected from known vulnerabilities. See the <a href="http://guides.rubyonrails.org/security.html">Ruby On Rails Security Guide</a> for an overview of potential issues and watch the <a href="https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-security">Ruby on Rails Security Mailing List</a> for announcements and discussion.</p>
<h3>Your Application’s Secret Token</h3>
<p>Rails uses a session store to provide persistence between page requests. The default session store uses cookies. To prevent decoding of cookie data and hijacking a session, Rails encrypts cookie data using a secret key. When you create a new Rails application using the <code>rails new</code> command, a unique secret key is generated. If you’ve used the Rails Composer tool to generate the application, the application’s secret token will be unique, just as with any Rails application generated with the <code>rails new</code> command.</p>
<p>The file <strong>config/secrets.yml</strong> contains secret tokens for development and production.</p>
<p>Take care to hide the secret token you use in production. Don’t expose it in a public GitHub repo, or people could change their session information, and potentially access your site without permission. It’s best to set the secret token in a Unix shell variable.</p>
<p>If you need to create a new secret token:</p>
<pre>
$ rake secret
</pre>
<p>The command <code>rake secret</code> generates a new random secret you can use. The command won’t install the key; you have to copy the key from the console output to the appropriate file.</p>
<h2>Troubleshooting</h2>
<h4>Problems with <span class="caps">RVM</span>
</h4>
<p>You can get help directly from the <span class="caps">RVM</span> team using the <span class="caps">IRC</span> (Internet Relay Chat) channel #rvm on irc.freenode.net:</p>
<p><a href="http://webchat.freenode.net/?channels=rvm">http://webchat.freenode.net/?channels=rvm</a></p>
<p>If you’ve never used <span class="caps">IRC</span>, it’s worthwhile to figure out how to use <span class="caps">IRC</span> because the <span class="caps">RVM</span> team is helpful and friendly. <span class="caps">IRC</span> on freenode requires registration (see <a href="http://en.wikipedia.org/wiki/Wikipedia:IRC/Tutorial#Nickname_registration">how to register</a>).</p>
<h4>Problems with “Segmentation Fault”</h4>
<p>If you get a “segfault” when you try <code>rails new</code>, try removing and reinstalling <span class="caps">RVM</span>.</p>
<h4>Problems with “Gem::RemoteFetcher::FetchError: SSL_connect”</h4>
<p>Ruby and RubyGems (starting with Ruby 1.9.3p194 and RubyGems 1.8.23) require verification of server <span class="caps">SSL</span> certificates when Ruby makes an Internet connection via https. If you run <code>rails new</code> and get an error “Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate” see this article suggesting solutions: <a href="http://railsapps.github.io/openssl-certificate-verify-failed.html">OpenSSL errors and Rails</a>.</p>
<h4>Problems with “Certificate Verify Failed”</h4>
<p>Are you getting an error “OpenSSL certificate verify failed” when you try to generate a new Rails app from an application template? See this article suggesting solutions: <a href="http://railsapps.github.io/openssl-certificate-verify-failed.html">OpenSSL errors and Rails</a>.</p>
<h2>Where to Get Help</h2>
<p>Your best source for help with problems is <a href="http://stackoverflow.com/questions/tagged/ruby-on-rails-3">Stack Overflow</a>. Your issue may have been encountered and addressed by others.</p>
<p>You can also try <a href="http://www.railshotline.com/">Rails Hotline</a>, a free telephone hotline for Rails help staffed by volunteers.</p>
<h2>Credits</h2>
<p>Daniel Kehoe wrote the article.</p>
<h4><a href="http://railsapps.github.io/"><img src="http://railsapps.github.io/images/join/join-railsapps.png" title="Join RailsApps" alt="Join RailsApps"></a></h4>
</div>
<div class="comments" id="comments">
<div class="content wikistyle gollum">
<h2>Comments</h2>
</div>
<p>Is this helpful? Your encouragement fuels the project. Please tweet or add a comment. Couldn't get something to work? For the example apps and tutorials, it's best to open an issue on GitHub so we can help you.</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
/* * * 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" -->
</div><!-- class="columns" -->
</div><!-- class="row" -->
<footer class="row">
<div class="large-12 columns">
<div class="row">
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Getting Started</dt>
<dd><a href="http://railsapps.github.io/ruby-and-rails.html">Ruby on Rails</a></dd>
<dd><a href="http://railsapps.github.io/what-is-ruby-rails.html">What is Ruby on Rails?</a></dd>
<dd><a href="http://learn-rails.com/learn-ruby-on-rails.html">Learn Ruby on Rails</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-tutorial">Rails Tutorial</a></dd>
<dd><a href="http://learn-rails.com/ruby-on-rails-tutorial-for-beginners">Ruby on Rails Tutorial for Beginners</a></dd>
<dd><a href="http://railsapps.github.io/installing-rails.html">Install Ruby on Rails</a></dd>
<dd><a href="http://railsapps.github.io/installrubyonrails-mac.html">Install Ruby on Rails - Mac OS X</a></dd>
<dd><a href="http://railsapps.github.io/installrubyonrails-ubuntu.html">Install Ruby on Rails - Ubuntu</a></dd>
<dd><a href="http://railsapps.github.io/rubyonrails-nitrous-io.html">Ruby on Rails - Nitrous.io</a></dd>
<dd><a href="http://railsapps.github.io/updating-rails.html">Update Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-composer/">Rails Composer</a></dd>
<dd><a href="http://railsapps.github.io/">Rails Examples</a></dd>
<dd><a href="http://railsapps.github.io/rails-examples-tutorials.html">Rails Starter Apps</a></dd>
</dl>
</div>
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Articles</dt>
<dd><a href="http://railsapps.github.io/rails-authorization.html">Rails Authorization</a></dd>
<dd><a href="http://railsapps.github.io/rails-google-analytics.html">Analytics for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-heroku-tutorial.html">Heroku and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-javascript-include-external.html">JavaScript and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-environment-variables.html">Rails Environment Variables</a></dd>
<dd><a href="http://railsapps.github.io/rails-git.html">Git and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-github.html">Rails GitHub</a></dd>
<dd><a href="http://railsapps.github.io/rails-send-email.html">Send Email with Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-haml.html">Haml and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-default-application-layout.html">Rails Application Layout</a></dd>
<dd><a href="http://railsapps.github.io/rails-html5-boilerplate.html">HTML5 Boilerplate for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-3-2-example-gemfile.html">Example Gemfiles for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-application-templates.html">Rails Application Templates</a></dd>
<dd><a href="http://railsapps.github.io/rails-product-planning.html">Rails Product Planning</a></dd>
<dd><a href="http://railsapps.github.io/rails-project-management.html">Rails Project Management</a></dd>
</dl>
</div>
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Tutorials</dt>
<dd><a href="http://railsapps.github.io/twitter-bootstrap-rails.html">Rails Bootstrap</a></dd>
<dd><a href="http://railsapps.github.io/rails-foundation.html">Rails Foundation</a></dd>
<dd><a href="http://railsapps.github.io/rails-omniauth/">OmniAuth Tutorial</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-devise.html">Rails Devise Tutorial</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html">Devise RSpec</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-bootstrap-devise-cancan.html">Devise Bootstrap</a></dd>
<dd><a href="http://railsapps.github.io/rails-devise-roles">Role-Based Authorization</a></dd>
<dd><a href="http://railsapps.github.io/rails-devise-pundit">Rails Authorization with Pundit</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-stripe-membership-saas">Rails Membership Site with Stripe</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-recurly-subscription-saas">Rails Subscription Site with Recurly</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-prelaunch-signup">Startup Prelaunch Signup Application</a></dd>
</dl>
<dl class="footer_nav">
<dt>RailsApps Profile</dt>
<dd><a href="https://plus.google.com/108039160165742774777?rel=author">Google</a></dd>
<dd><a href="https://plus.google.com/117374718581973393536" rel="publisher">Find us on Google+</a></dd>
</dl>
</div>
</div>
</div>
</footer>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/js/foundation.min.js"></script>
<script>
$(document).foundation();
</script>
</body>
</html>