-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
204 lines (127 loc) · 14 KB
/
atom.xml
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[]]></title>
<link href="http://gotealeaf.github.io/resources/atom.xml" rel="self"/>
<link href="http://gotealeaf.github.io/resources/"/>
<updated>2014-02-06T14:19:15-05:00</updated>
<id>http://gotealeaf.github.io/resources/</id>
<author>
<name><![CDATA[Tealeaf Academy]]></name>
</author>
<entry>
<title type="html"><![CDATA[Install Ruby on Rails for Hackers]]></title>
<link href="http://gotealeaf.github.io/resources/blog/2014/02/06/install-ruby-on-rails-for-hackers/"/>
<updated>2014-02-06T10:17:11-05:00</updated>
<id>http://gotealeaf.github.io/resources/blog/2014/02/06/install-ruby-on-rails-for-hackers</id>
<content type="html"><![CDATA[<p>(Updated Feb 4 2014)</p>
<h1>Step 1. Upgrade Your System to OS X Mavericks</h1>
<p>If you have a not-so-ancient Mac model (generally, 2008 or newer), you should <a href="https://www.apple.com/osx/how-to-upgrade/">upgrade your system to OS X Mavericks</a>. It comes with the latest application features, energy efficiency and performance optimization from Apple, and it’s completely free. Do this first before the rest of the steps in this guide.</p>
<h1>Step 2. Install XCode Command Line Developer Tools</h1>
<p>This used to involve a much lengthy process, but thanks to a newly released package by Apple, all you have to do is to run the following command in your terminal.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>xcode-select --install
</span></code></pre></td></tr></table></div></figure>
<h1>Step 3. Install Homebrew</h1>
<p>Type the following command in your terminal:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>ruby -e <span class="s2">"$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"</span>
</span></code></pre></td></tr></table></div></figure>
<h1>Step 4. Install Ruby with rbenv</h1>
<p>Your Mac already ships with Ruby (that’s how we can use it to install homebew in the last step). However, it’s still a good idea to use a Ruby Version Manager like <code>rbenv</code> to install Ruby because 1) the system Ruby is likely outdated and 2) you may need to work on multiple projects on different versions of Ruby. A Ruby Version Manager makes organizing and switching between Rubies a breeze.</p>
<p>First we can use homebrew to install rbenv:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>brew update
</span><span class='line'>brew install rbenv ruby-build rbenv-gem-rehash
</span></code></pre></td></tr></table></div></figure>
<p><code>rbenv</code> by itself only manages switching ruby versions. <code>ruby-build</code> and <code>rbenv-gem-rehash</code> are both <code>rbenv</code> extensions. <code>ruby-build</code> allows you to install rubies with <code>rbenv</code> and <code>rbenv-gem-rehash</code> automatically installs new shims for you whenever a new Ruby gem is installed so you don’t have to rehash yourself.</p>
<p>Open up your the `~/.bashrc’ file, and put this line on the bottom:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">eval</span> <span class="s2">"$(rbenv init -)"</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now you are ready to install Ruby with <code>rbenv</code>. At the time of this writing, the latest stable Ruby version is 2.1.0, so let’s install that.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>rbenv install 2.1.0-p0
</span></code></pre></td></tr></table></div></figure>
<h1>Step 5. Install git and set up Github account</h1>
<p>Git is a powerful version control system and is very popular in the Ruby community. If you followed this guide, you should already have git installed as part of the XCode Command Line Developer Tools. You may also want to install git separately with homebrew to make it easier to upgrade to latest releases.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>brew install git
</span></code></pre></td></tr></table></div></figure>
<p>Now tell git your name and email that it will use for your future commits.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git config --global user.name <span class="s2">"Your Name Here"</span>
</span><span class='line'>git config --global user.email <span class="s2">"[email protected]"</span>
</span></code></pre></td></tr></table></div></figure>
<p>Github is the leading platform for source code hosting and collaboration. If you don’t have an account yet, go ahead and sign up for one at <a href="https://github.com.">https://github.com.</a> Make sure you sign up with the same email address from the step above.</p>
<p>For easier authentication with Github when you push or pull code, follow <a href="https://help.github.com/articles/generating-ssh-keys">this guide</a> to set up ssh keys for your Mac.</p>
<h1>Step 6. Set up Sublime Text 2 as code editor</h1>
<p>If you already have an editor of choice, such as Vim or Emacs, you are all set and can skip this step! If you are not familiar with code editors, Sublime Text 2 is an excellent choice and you can download it <a href="http://www.sublimetext.com/2">here</a>.</p>
<p>After you install it, run the following command so you can easily launch the editor from your terminal directly:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>ln -s <span class="s2">"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"</span> ~/bin/subl
</span></code></pre></td></tr></table></div></figure>
<p>The convention for Ruby programs is to use two spaces as indentation, so follow <code>Sublime Text 2 => Preferences => Settings - User</code> and add these lines.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="o">{</span>
</span><span class='line'><span class="s2">"tab_size"</span>: 2,
</span><span class='line'><span class="s2">"translate_tabs_to_spaces"</span>: <span class="nb">true</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<h1>Step 7. Create a New Rails Application</h1>
<p>If you don’t have a directory to hold all your development projects yet, you can create that directory like below:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir ~/projects
</span></code></pre></td></tr></table></div></figure>
<p>Now you can create a Rails project in that directory:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">cd</span> ~/projects
</span><span class='line'>gem install rails
</span><span class='line'>rails new name_of_your_new_app
</span></code></pre></td></tr></table></div></figure>
<p>Wait until the the last step finishes, and you just created your first Rails project! You can verify that you set up Rails by first starting the server</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">cd</span> ~/projects/name_of_your_new_app
</span><span class='line'>rails s
</span></code></pre></td></tr></table></div></figure>
<p>Now open up your browser and type in the address bar <code>http://localhost:3000</code> and if you see a welcome page, your app is running locally.</p>
<h1>Optional Step 1. Use iTerm 2, zsh and oh-my-zsh to set up an awesome looking and easily customizable terminal</h1>
<p>Download and Install <a href="http://www.iterm2.com/#/section/home">iTerm 2</a>. It comes with more features and easier to customize than the built in Terminal.</p>
<p>Optionally, you can further customize iTerm 2 to your liking! Here are some of my preferences.</p>
<ul>
<li>Under “Genereal”, check “Copy to clipboard on selection”.</li>
<li>Under “Profile” => “Colors”, click on “Load Presets”, then choose “Dark Background”;</li>
<li>Under “Profile” => “Text”, change the font to one that you enjoy looking at. My favorite is 20pt <a href="http://www.marksimonson.com/fonts/view/anonymous-pro">Anonymous Pro</a> with Anti-aliased. You have to download it first and install it into your Mac’s font book before you can use it.</li>
<li>Under “Keys”, define a hotkey to hide/show the terminal window. This is much faster than having to Command+Tab through opened windows and find iTerm 2.</li>
</ul>
<p>Zsh is an alternative shell to the default bash shell that comes with Mac. It adds nice features such as smart tab completions, but what really sets it apart is its scriptability. Together with oh-my-zsh, an open source zsh configuration management framework, it becomes really easy to customize both the look and functionality of your terminal.</p>
<p>Your Mac should already come with zsh. To use zsh, go to iTerm 2 => Preferences => Profiles => General and in the “Command” section, select “Command”, and type <code>/bin/zsh</code> in the box after it.</p>
<p>Now you can install oh-my-zsh with</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
</span></code></pre></td></tr></table></div></figure>
<p>Now you can customize the <code>~/.zshrc</code> file.</p>
<ul>
<li>If you have your settings in <code>~/.bash_profile</code>, you may want to copy them over to <code>/.zshrc</code>.</li>
<li>Find the <code>plugins=(git)</code> line and add <a href="https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins">more plugins</a>. Here is the plugins I am using:</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">plugins</span><span class="o">=(</span>git bundler brew osx vagrant wd gem<span class="o">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>The bunlder plugin is especially useful when you work on Rails applications as it saves you from typing those “bundle exec”’s in front of commands like <code>rails</code>, <code>rake</code>, <code>rspec</code>, etc!</p>
<p>If you do not like the default theme, you can pick from one of the many themes that come with oh-my-zsh. You can see the list of themes <a href="https://github.com/robbyrussell/oh-my-zsh/wiki/themes">here</a> and <a href="http://zshthem.es/all/">here</a>.</p>
<p>If you feel really adventurous, you can even build your own theme! Take a look at <a href="https://github.com/robbyrussell/oh-my-zsh/tree/master/themes">how themes are implemented</a>, and copy/tweak/build one exactly to your taste!</p>
<h1>Optional step 2. Install Postgresql as a production quality database</h1>
<p>By default, Rails uses sqlite3 as the default development database. It’s a nice database but probably not one that you want to use in production. Postgresql is a solid, production quality relational database and works well with Rails. It’s generally a good idea to set up your local database to match the database on the production environment.</p>
<p>The easiest way to use Postgresql on Mac is to download and install the <a href="http://postgresapp.com/">Postgres.app</a></p>
<p>With Postgresql running, add <code>gem 'pg'</code> to the Gemfile in your rails project and run <code>bundle install</code> to install the Postgresql Ruby driver.</p>
]]></content>
</entry>
</feed>