Installing node and npm on my Mavericks MacBook Pro

npm-yo-grunt-bower

Package management is great. Yes, it is… WHEN IT WORKS. At least that was my attitude before.

As I anticipate release of Zurb Foundation 5 on November 21st, I couldn’t wait for it to go live. So, I decided to peak into their github branches. They are using Grunt in their process, and Foundation will be included in bowser. And documentation is built with Grunt using assemble.io. OK, those things are things that I have not have time to play with. I hear all the good things that node.js and its npm installed application can do… a lot of it like magic, they say. I just have never done it, partly because I was using Red Hat’s rpm when it went from Red Hat to Fedora and it stop working, and more recently, something went wrong with ruby version control RVM thing.

I am still a designer-turned-himself-into-developer, and even with all of my geekiness, still don’t quite understand, or still have a fear, about “computer science”.

Anyway. I decided that the time is now. Just do it.

So, here are my notes while I struggled through it all. I will likely have to do it again when I get a new computer or anything like that. I figured it would be good to leave trace.

Note: If you are here for “npm: command not found” problem, skip the middle part when I struggle with it and go to the end of the post for solution. It’s a permission issue and you need to run this: sudo chown -R $USER /usr/local

I needed Bower, because with it, installing foundation would be a breeze. Done like this: bower install foundation

But, to get bower, I needed npm. Once I have npm, all I had to do was: npm install -g bower

How easy is that? So, I searched how to install node and npm. I found a blog post: Installing Node and NPM, however a bit old since written in December 10, 2010.

To do that, I needed Xcode. Do I have that?

I did have XCode, (just searched through spotlight) but needed to install/upgrade component. Version That I have is Version 5.0.2 (5A3005) done this through App Store.

I am now looking into around step 4 on the blog post above, I’m getting nervous. His Gist of “Node and RPM in 30 seconds shell script” is quite nice, but didn’t feel like firing command via command line without understanding what I was doing. Then I found this blog post: Setting up Node.js and npm on Mac OSX I see this bit:

There are now packages available for OSX and Windows if you prefer a one click install for Node.js and NPM.

Sweet. Yes I do prefer a one click install. And here it is, on nodejs.org homepage.

I downloaded: Mac OS X Installer (.pkg) – Universal

Run it, and yay, I got the following message.

The installation was completed successfully

Node was installed at
/usr/local/bin/node

npm was installed at
/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

That was easy. But wait. Making sure if I have node and npm, I tested by running command like which node; which npm; node -v; npm -v; which should print the path, and -v prints version number of installed applciations.

But I get this -bash: npm: command not found

Maybe I needed to do set $Path?
export PATH="$PATH:/usr/local/git/bin:/usr/local/bin"
That was not it.

Then I read this: Mac OS X NPM install probem “-bash : npm: command not found”

Very similar. He says at the end

@mfncooper You were right. It was a permissions problem! No one had access to the file. Ran chmod on /usr/local/lib and set permissions to give full access to everyone. Then I ran the shell script again as a sudo user. Worked perfectly. Thanks.

What so, change the usr/local/lib permission? sudo chmod 777 /usr/local/lib/ then ran the pkg again.
Now when I do

$ which npm
/usr/local/bin/npm

Nice! Looks like both the node and npm is running.

$ node -v
v0.10.22
$ npm -v
1.3.14

But then bower and grunt install failed.

$ npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 200 https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli/-/grunt-cli-0.1.11.tgz
npm http 200 https://registry.npmjs.org/grunt-cli/-/grunt-cli-0.1.11.tgz
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

Mmm. Found this (What did we do before Google?):
Error when installing bower

“So the fix was to simply sudo su - then run npm install bower -g.”

Whoa, it works.

Well, kind of. Wasn’t perfect. Still lots of errors. But then also, doing everything sudo is kind of not good.

More gopgle: NPM throws error without sudo (What did developers do before stackoverflow???)

sudo chown -R `whoami` ~/.npm

Would this do?

Nope. Similar results.

Maybe this error message is something?
npm ERR! Please try running this command again as root/Administrator.

Google lead me to this awesome blog post: npm install -g?—?ERR! Please try running this command again as root/Administrator. (Brilliant title!)

This is a permissions issue and the fix, courtesy of Tim Schaub, is to recursively change the owner of the files in your /usr/local folder to the current user:

sudo chown -R $USER /usr/local

That did it. Awesome.

Says original solution provider Tim Schaub:

That sets your user account as the owner of the /usr/local directory, so that you can just issue normal commands in there. Then you won’t ever have to use sudo when you install node or issue npm commands.

It’s much better this way. /usr/local is supposed to be the stuff you installed, after all.

Thank you good people of interwebz. Saved my day, yet again. Now I am off to Yeomaning, and then Grunting, then Bowering! (Whatever those things are!)

11 Responses to “Installing node and npm on my Mavericks MacBook Pro”

  1. Gabriel Florit

    Thanks Daigo! I was stuck on “npm: command not found”. Changing permissions on the directory did the trick.

  2. Thank you for such a clear description of your journey! They really should include this in the “how to install” bits of these packages.

  3. Enjoyed reading that. You describe a developers day well. Loading something like node/npm should be easier. It must have been easier at one point I had it installed. I think moving to Mavericks botched that and had to remove it. Now starting again.

  4. Thank you so much – my biggest hurdle migrating to Foundation 5 was all this Bower/Grunt installation weirdness.

  5. This did not work. I entered this exact command: sudo chown -R $USER /usr/local
    I entered my password, and then when I tried both sudo npm install -g bower and npm install -g bower I still got npm: command not found. What is the problem?

  6. Ha…. wait, I needed to install node.js first, THEN run the sudo chown command. Now it works. Thank you for the article.

  7. Thanks for noting your experiences, it also works on Mountain Lion. Now off to install Claymate and, at long last, my first Gumgy build.

  8. This post helped. My problem was that npm wasn’t even listed in /usr/local/bin. Had to reinstall node via homebrew. Oy!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>