RSS Log in
 

This is step 5 of Installing Ruby on a Mac and covers Ruby Gems and Pow.

 

Getting Started

Step 1 - Xcode, Homebrew and Git

Step 2 - Wget and OH MY ZSHELL

Step 3 - RVM

Step 4 - Ruby

_Step 5 – Gems and Pow_

Step 6 – Databases and Rails

Hello World

 

Gems (optional)

Gems are software packages. They are either Ruby applications themselves or libraries that can be used to extend other Ruby applications. They are effectively reusable components. RubyGems is the command-line utility used to download and install gems on your machine. It has been part of the Ruby installation since version 1.9.2.

 

Before using RubyGems, make sure you’ve updated to the latest version:

$ gem update --system

 

As usual verify the version:

$ gem --version

I currently have version 1.8.11 installed.

 

Now since we’re just getting setup, I’m not going to go crazy. I’ll download only one gem: powder.

$ gem install powder

The GitHub project homepage doesn’t say much but it’s basically a utility that helps you manage Pow

 

Pow (optional)

From the project’s homepage:

“Pow is a zero-config Rack server for Mac OS X.”

 

I really needed to break this down to actually understand what this means. Put “simply” Pow is a self-contained (i.e. no dependencies, no gems to install, no Apache extensions to compile, etc.) web server that doesn’t require any configuration, runs on Mac OS X as a user without root privileges and is built with Ruby Rack - an API that sits in between a web server and an application. Rack connects them together by passing HTTP requests from the server to an application and the response from the application back to the server.

…Or in other words Pow is meant to simplify and speed up Ruby on Rails development on your local machine. Pow uses Node.js and CoffeeSript. You can check out the source code for Pow on the GitHub Repository page.

 

To install it, you can either use cURL:

$ curl get.pow.cx | sh

 

Or better, make use of our Powder gem:

$ powder install

 

Once done, we’re going to test the install. Open your Web browser and type in the following http://hello.dev.

If Pow is running, you should get an Application not found error as shown here:

Running Pow

 

Now let’s create a simple static site.

1. Create a folder called Hello somewhere in your home directory

2. Create a sub-folder called public

3. Add a new HTML file in that folder and call it index.html

<!DOCTYPE html>
<html>
<head>
  <title>index</title>
</head>
<body>
  <div>
    <header>
      <h1>Pow Test</h1>
    </header>
    <div>Hello World</div>
    <footer>
     <p>by Pascal</p>
    </footer>
  </div>
</body>
</html>

You should end up with a structure like this:

Project Folder

4. Open terminal and navigate to the Hello directory

5. Create a symlink (see side note below) to it using Powder:

$ powder link

You should get this message:

Your application is now available at http://Hello.dev/

 

To check that the symlink was created, unhide all invisible files and go to (Shift + CMD + G) the dot Pow directory ~/.pow

Pow Hosts

 

If you bring up the info window (CMD + I) for the Hello folder, you find that an alias was created and see the target location:

Hello Info

6. Now we can open the site:

$ powder open

 

The site is live!

Hello Dev

 

So what’s happening here?

From Pow User’s Manual (using our Hello World example), Pow:

“…sets up a system hook so that all DNS queries for a special top-level domain (.dev) resolve to your local machine…

The name of the symlink (Hello) determines the hostname you use (hello.dev) to access the application it points to (~/Dev/Projects/Hello).”

 

Pretty cool stuff!

 

Side Note

A symlink (also symbolic link or soft link) is a file that contains a reference to a target file or directory. When an application points to a symlink, it's transparently redirected to the original copy of the file or folder. Contrary to an alias, if you rename the target, a symlink will stop working.

 

To complete our Ruby Dev installation, we’ll setup Ruby on Rails next…

 

If you see any inaccuracies, things that should be added, removed or corrected, please either leave a comment or drop me an email. Thanks.


Comments are closed
© Copyright 2012 TheBooleanFrog Powered by: BlogEngine.NET|Credits|Subscribe via RSS

Follow

twitter linkedin linkedin rss

TheBooleanFrog

Programming sticky notes and other distractions...