CoffeeScript Cafe

CoffeeScript tutorials, examples, and news

Setting Up Your Mac OS X CoffeeScript Development Environment

If you want to independently write CoffeeScript (i.e. outside of Rails or another framework that automatically supports CoffeeScript) you’ll need to install a CoffeeScript compiler.

The standard compiler used by the community is the Node.js package “coffee-script”. You can use it to launch an interactive CoffeeScript session or compile CoffeeScript source files to JavaScript. It also provides tools allowing you to dig in and analyze the source code.

Here are the steps to get that up and running on Mac OS X. Sorry Windows and Linux folks, I don’t have tutorials written for those platforms yet. But your steps will essentially be: 1) install Node.js, 2) use npm to install coffee-script.

Step 1: Install Homebrew

Homebrew makes installing compiled from source software super easy on the Mac. Use it.

These official Homebrew installation instructions will get you setup in no time.

Step 2: Install Node.js

This one is super easy, just run the following command after you’ve installed Homebrew.

$ brew install node

Step 3: Install npm

$ curl | sh

Step 4: Install coffee-script

$ npm -g install coffee-script

The -g flag says to install the package globally. The coffee-script package installs some executable scripts so installing it globally will make running them easier.

After that last command you should now have coffee available as a command. You can test that by running coffee -v:

$ coffee -v
CoffeeScript version 1.1.3

At this point the official CoffeeScript documentation is well worth a perusal if you haven’t seen it already.

Step 5: Install the TextMate Bundle

You do use TextMate, right? Ok good. Open the terminal and run the following commands.

$ mkdir -p ~/Library/Application\ Support/TextMate/Bundles
$ cd ~/Library/Application\ Support/TextMate/Bundles
$ git clone git:// CoffeeScript.tmbundle
$ osascript -e 'tell app "TextMate" to reload bundles'

If you get the error coffee: command not found when trying to compile CoffeeScript in TextMate you just need to add “/usr/local/bin” to the TextMate path. Like this:

Step 6: Fix “coffee: command not found” TextMate Bundle error

  1. Open TextMate
  2. TextMate > Preferences
  3. Click the “Advanced” tab
  4. Click “Shell Variables”
  5. Find the “PATH” variable and double click its value
  6. Append :/usr/local/bin

At that point your CoffeeScript bundle should behave. No need for a restart.

Next Time

Alright! You’ve got a local CoffeeScript environment to play with. Go you!

Next post we’ll actually do something with CoffeeScript, and I’ll show you a technique for quickly incorporating CoffeeScript into a development project.

Web Analytics