× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Setup a basic rails environment in OSX

Paulo Abreu
Feb 08, 2015
<p>Rails newcomers feel frustrated with rails setup, finding it more difficult than it should be.</p> <h1>Setup</h1> <p>This basic setup is based in <a href="http://brew.sh/">H</a><a href="http://brew.sh">omebrew</a> and <a href="http://rvm.io/">RVM</a> tools.</p> <p><span style="color:rgb(95, 99, 102)"><strong>NB</strong>: </span><span style="color:rgb(95, 99, 102)">I recommend you to read Homebrew and RVM documentation</span><span style="color:rgb(95, 99, 102)"> as the way of installing those tools may have </span><span style="color:rgb(95, 99, 102)">changed</span><span style="color:rgb(95, 99, 102)">.</span></p> <p> </p> <h2>Xcode and Apple command-line tools installation</h2> <p>Go to App Store and install Xcode. Run Xcode and accept the Apple license. Open the terminal and type:</p> <pre><code>xcode-select --install</code></pre> <p> </p> <h2>Homebrew installation</h2> <blockquote> <p>Homebrew installs the stuff you need that Apple didn’t.</p> </blockquote> <p>Type:</p> <pre><code>ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code></pre> <p> </p> <h2>Rvm installation</h2> <p>Type:</p> <pre><code>\curl -sSL https://get.rvm.io | bash -s stable</code></pre> <p>Which will install RVM as a user ($HOME/.rvmrc). You <span style="color:rgb(95, 99, 102)">should follow any additional information that the setup displays into the terminal. You also need to </span>load your ~/.bashrc typing:</p> <pre><code>source ~/.bashrc</code></pre> <p>Alternatively, you may close and reopen the terminal.</p> <p> </p> <h1>Ruby Installation</h1> <p>Type:</p> <pre><code>rvm install 2.2</code></pre> <p>And set it as the default:</p> <pre><code>rvm use 2.2 --default</code></pre> <p> </p> <h1>Rails installation</h1> <p><span style="color:rgb(95, 99, 102)">I like to configure rvm projects to automate ruby switching and promote gem isolation between my rails projects. For that I use the following command:</span></p> <pre><code>rvm --ruby-version use &lt;ruby-version&gt;@&lt;project-name&gt; --create</code></pre> <p> </p> <h3>An example</h3> <p>Lets imagine that I want to build a codementor project with ruby 2.2. I need to create a ~/projects/codementor directory and setup the project.</p> <pre><code>mkdir -p ~/projects/codementor cd ~/projects/codementor rvm --ruby-version use 2.2@codementor --create</code></pre> <p>Next I need to install rails gems:</p> <pre><code>gem install rails</code></pre> <p>And create a new rails project:</p> <pre><code>rails new codementor-app</code></pre> <h3> </h3> <h3>RVM pojects explained</h3> <p>The <code>rvm --ruby-version use &lt;ruby-version&gt;@&lt;project-name&gt; --create</code> command creates two hidden files that will be loaded every time you switch to codementor directory:</p> <pre><code>$ cd ~/projects/codementor $ ls -la total 16 drwxr-xr-x 4 mentor staff 136 Feb 8 12:27 . drwxr-xr-x 31 mentor staff 1054 Feb 8 12:26 .. -rw-r--r-- 1 mentor staff 11 Feb 8 12:27 .ruby-gemset -rw-r--r-- 1 mentor staff 11 Feb 8 12:27 .ruby-version</code></pre> <p>When you perform the command, rvm displays:</p> <pre><code>$ rvm --ruby-version use 2.2@codementor --create ruby-2.2.0 - #gemset created /Users/mentor/.rvm/gems/ruby-2.2.0@codementor ruby-2.2.0 - #generating codementor wrappers.......... Using /Users/mentor/.rvm/gems/ruby-2.2.0 with gemset codementor</code></pre> <p>The command creates a directory '~/.rvm/gems/ruby-2.2.0@codementor':</p> <pre><code>ls -ls ~/.rvm/gems/</code></pre> <p><span style="color:rgb(95, 99, 102)">Where rvm will insert everything related to codementor project, gems included:</span></p> <pre><code>ls -ls ~/.rvm/gems/ruby-2.2.0@codementor/gems</code></pre> <p>Type <code>rvm gemset help</code> to get all the available options to manage gemsets such as listing all gemsets, delete or empty a gemset.</p> <h1> </h1>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus