installing karma through npm times out on phantomjs-Collection of common programming errors

I am trying to install karma via npm, but it keeps timing out. I downloaded the file with curl and installed phantomjs manually, but npm still throws an error when I try to install karma. I tried copying the file into the path that npm says it’s saving to, but that doesn’t work (running the install also deletes the directory that I create).

This is what I’m running:

sudo npm install -g karma

This is what’s happening:

> [email protected] install /usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs
> node install.js

Downloading http://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
Saving to /usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/phantomjs/phantomjs-1.9.1-linux-x86_64.tar.bz2

events.js:77
        throw er; // Unhandled 'error' event
              ^
Error: connect ETIMEDOUT
    at errnoException (net.js:947:11)
    at Object.afterConnect [as oncomplete] (net.js:938:19)
npm ERR! weird error 8
npm ERR! not ok code 0

I find it odd that it’s still trying to install phantomjs even after I installed it manually on my system. What can I do in order to make this work, I have the file downloaded, and even installed it, and it appears to be working. For some reason, npm just doesn’t like it.

  1. Fixed.. it was necessary to do sudo n stable instead of sudo n latest – apparently cannot install karma with the latest version of node.js