Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing node with homebrew on OSX. Npm not found

I previously had a working install of node and npm on OSX, but when updating npm something went wrong. I then messed things up more using homebrew to try and link, uninstall, and reinstall node. Somewhere along the way my original node install, which used the installer from nodejs.com, and my brew usage on node conflicted. I finally got node reinstall with homebrew, but when I try running npm I get the npm command not found. Here is the message I get when running brew install node.

$ brew install node
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/node-0.10.3
Already downloaded: /Library/Caches/Homebrew/node-0.10.32.mavericks.bottle.tar.gz
==> Pouring node-0.10.32.mavericks.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> make install
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /usr/local/lib/node_modules/npm/npm-debug.log
npm ERR! not ok code 0
make: *** [install] Error 3
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Summary
🍺  /usr/local/Cellar/node/0.10.32: 1678 files, 19M

I tried running the postinstall node as stated in the error message but then get this error message.

$ brew postinstall node
==> make install
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /usr/local/lib/node_modules/npm/npm-debug.log
npm ERR! not ok code 0
make: *** [install] Error 3

Any ideas of how to fix my node install?

Here's the last part of the npm-debug.log

30 silly resolved     readmeFilename: 'README.md',
30 silly resolved     _id: '[email protected]',
30 silly resolved     _shasum: 'c0b916c7b6363d1fbde42c2d1420aca8e05a4118',
30 silly resolved     _from: '.' } ]
31 info install [email protected] into /usr/local/lib
32 info installOne [email protected]
33 verbose lib/node_modules/npm unbuild
34 info preuninstall [email protected]
35 info uninstall [email protected]
36 verbose true,/usr/local/lib/node_modules,/usr/local/lib/node_modules unbuild [email protected]
37 verbose /usr/local/bin,[object Object] binRoot
38 verbose lib/node_modules/npm unbuild
39 info preuninstall [email protected]
40 info uninstall [email protected]
41 verbose true,/usr/local/lib/node_modules,/usr/local/lib/node_modules unbuild [email protected]
42 verbose /usr/local/bin,[object Object] binRoot
43 error error rolling back Error: EACCES, unlink '/usr/local/share/man/man5/npm-folders.5'
43 error error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/share/man/man5/npm-folders.5']
43 error error rolling back   errno: 3,
43 error error rolling back   code: 'EACCES',
43 error error rolling back   path: '/usr/local/share/man/man5/npm-folders.5' }
44 error Error: EACCES, unlink '/usr/local/share/man/man5/npm-folders.5'
44 error  { [Error: EACCES, unlink '/usr/local/share/man/man5/npm-folders.5']
44 error   errno: 3,
44 error   code: 'EACCES',
44 error   path: '/usr/local/share/man/man5/npm-folders.5' }
45 error Please try running this command again as root/Administrator.
46 error System Darwin 13.4.0
47 error command "node" "/usr/local/lib/node_modules/npm/cli.js" "install" "-g" "-f"
48 error cwd /usr/local/lib/node_modules/npm
49 error node -v v0.10.32
50 error npm -v 1.4.24
51 error path /usr/local/share/man/man5/npm-folders.5
52 error code EACCES
53 error errno 3
54 error stack Error: EACCES, unlink '/usr/local/share/man/man5/npm-folders.5'
55 verbose exit [ 3, true ]
like image 222
mikeLspohn Avatar asked Oct 11 '14 01:10

mikeLspohn


2 Answers

Do yourself a favor and use nvm. It helps you manage Node versions and you won't need root priviledges to use it.

Install nvm

Here we're using curl to get the install script for nvm and interpreting that script using bash.

curl https://raw.githubusercontent.com/creationix/nvm/v0.17.2/install.sh | bash

Install node + npm

This command will figure out the latest stable release of node and install it in your system.

nvm install stable

(currently bugged, use nvm install 0.10 for now...)

Persist

So that nvm configures your terminal whenever you open a new window, run this command too:

nvm alias default stable

(currently bugged, use nvm alias default 0.10 for now...)

Use

Now you can use Node as usual!

node foo

Read nvm documentation!

Here: https://github.com/creationix/nvm

like image 158
bevacqua Avatar answered Oct 03 '22 16:10

bevacqua


The solution to permissions problems with Homebrew is often sudo chown -R $(whoami) $(brew --prefix). If you ever used npm as root, which should not be necessary, some of the files in its directory tree will be owned by root, which will cause permissions problems on upgrade.

like image 41
Tim Smith Avatar answered Oct 03 '22 16:10

Tim Smith