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.
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.
Step 3: Install npm
Step 4: Install coffee-script
-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
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.
1 2 3 4
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
- Open TextMate
- TextMate > Preferences
- Click the “Advanced” tab
- Click “Shell Variables”
- Find the “PATH” variable and double click its value
At that point your CoffeeScript bundle should behave. No need for a restart.
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.