Fixing a default Node.JS install to work with Heroku on OS X

04 Jan 2012

Convenience of a Pkg

When getting started with Node.js, I found it helpful that Joyent distributes a pkg installer for the OS X platform. Next, next, finish and the pkg installs the latest version of the platform along with npm, the management system for node modules and resources.

Running a Compatible Heroku Version

Everything ran smoothly till I attempted to add Heroku's package management stack and was greeted with this error.

npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: express@2.2.0
npm ERR! Required: {"node":">= 0.4.1 < 0.5.0"}
npm ERR! Actual:   {"npm":"1.1.0-beta-4","node":"0.6.6"}

Heroku's cedar stack utilizes an older version, v0.4.7.

Enter nvm, Node Version Manager, available from creationix on github. This allows multiple versions of node to be installed on the system with an added switching utility. A compiler is required for nvm, but having Xcode installed satisfies this.

The install is another great utility requiring only a single command.

git clone git://github.com/creationix/nvm.git ~/.nvm
. ~/.nvm/nvm.sh

At this point, I added that last line to my ~./profile so that nvm is available on each terminal session.

Installing a new Node.js version is straight forward.

nvm install v0.4.7

Then, when it's time to switch versions, I use this.

nvm use v0.4.7

It's helpful if all new terminal sessions use a default version.

nvm alias default v0.4.7

Going back to heroku, I was greeted with a new error message.

Error: npm doesn't work with node v0.4.7

My Node.js pkg install was interferring with nvm.

Removing Node.JS pkg install

Node.js installs itself and npm in /usr/local/bin/ while nvm keeps itself and npm within its own directory. To keep things tidy and in working order, I removed the Node.js pkg install.

Conveniently, npm comes with an uninstall method.

nvm deactivate
sudo npm uninstall npm -g

The Node.js platform requires a little more work as it does not come with an uninstall. When OS X runs a package, it keeps a bill of materials file for the install. These live in /Library/Receipts. Investigating a bom requires the lsbom utility.

lsbom /Library/Receipts org.nodejs.pkg.bom

This will list out each individual file, but a quick glance told me Node.js was installed in the following directories.

/usr/local/bin/node
/usr/local/bin/node-waf
/usr/local/bin/npm
/usr/local/include/node/
/usr/local/lib/node
/usr/local/lib/node_modules/

It is just a matter of removing each directory and contents

sudo rm -rf ./bin/node
...

After that, things have been running smoothly.