简体   繁体   中英

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: 'npm@1.4.24',
30 silly resolved     _shasum: 'c0b916c7b6363d1fbde42c2d1420aca8e05a4118',
30 silly resolved     _from: '.' } ]
31 info install npm@1.4.24 into /usr/local/lib
32 info installOne npm@1.4.24
33 verbose lib/node_modules/npm unbuild
34 info preuninstall npm@1.4.24
35 info uninstall npm@1.4.24
36 verbose true,/usr/local/lib/node_modules,/usr/local/lib/node_modules unbuild npm@1.4.24
37 verbose /usr/local/bin,[object Object] binRoot
38 verbose lib/node_modules/npm unbuild
39 info preuninstall npm@1.4.24
40 info uninstall npm@1.4.24
41 verbose true,/usr/local/lib/node_modules,/usr/local/lib/node_modules unbuild npm@1.4.24
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  npm@1.4.24 { [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 ]

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

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.

I am on OSX and fixed this issue by downloading and installing the latest version from http://nodejs.org/ . This will get you the latest node and npm.

I know this isn't going to be the accepted answer, but you probably have done something like sudo npm -g install XXX previously and now have some permission trouble.

There are two spots where this trouble will get you:

sudo chown -R `whoami`:staff /Users/`whoami` /usr/local

The gist is that Node keeps some things in /usr/local and NPM keeps some things in your HOME directory. If you touched any of those with sudo you'll have bad time.

If npm -v gives an error after installing node , it shows that symlink is not created.Whenever an install via brew happens , there will be a symlink creation. If installing some packages results in warning , u have to use the export command shown in the warning at ur respective workspace folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM