重新安装 Mac OS X 后 npm 无法工作

5

我不得不在我的笔记本电脑上重新安装Mac OS X Mavericks。现在npm无法正常工作。但是,node仍然存在于笔记本电脑上,并且npm在$PATH中。

christohersmbp3:angular-phonecat christopherspears$ npm install
-bash: npm: command not found
christohersmbp3:angular-phonecat christopherspears$ node --version
v0.10.26
christohersmbp3:angular-phonecat christopherspears$ npm start
-bash: npm: command not found
christohersmbp3:angular-phonecat christopherspears$ echo $PATH
/usr/local/share/python:/Users/christopherspears/.rbenv/bin:/Users/christopherspears/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

我实际上很容易地让node运行起来:

christohersmbp3:~ christopherspears$ node
> console.log('hello node');
hello node
undefined
> 
(^C again to quit)
> 

有没有想法如何修复这个问题或者我只需要重新安装Node.js?
更新:
我一直试图卸载和重新安装Node.js,但遇到了一个问题:
christohersmbp3:angular-phonecat christopherspears$ brew uninstall node
Uninstalling /usr/local/Cellar/node/0.10.26...
christohersmbp3:angular-phonecat christopherspears$ brew install node
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/node-0.10.26.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring node-0.10.26.mavericks.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using:
  brew link node

Possible conflicting files are:
/usr/local/bin/node
/usr/local/include/node/zlib.h
/usr/local/include/node/zconf.h
/usr/local/include/node/v8stdint.h
/usr/local/include/node/v8.h
/usr/local/include/node/v8-testing.h
/usr/local/include/node/v8-profiler.h
/usr/local/include/node/v8-preparser.h
/usr/local/include/node/v8-debug.h
/usr/local/include/node/uv.h
/usr/local/include/node/uv-private/uv-win.h
/usr/local/include/node/uv-private/uv-unix.h
/usr/local/include/node/uv-private/uv-sunos.h
/usr/local/include/node/uv-private/uv-linux.h
/usr/local/include/node/uv-private/uv-darwin.h
/usr/local/include/node/uv-private/uv-bsd.h
/usr/local/include/node/uv-private/tree.h
/usr/local/include/node/uv-private/stdint-msvc2008.h
/usr/local/include/node/uv-private/ngx-queue.h
/usr/local/include/node/openssl/opensslconf.h
/usr/local/include/node/node_version.h
/usr/local/include/node/node_object_wrap.h
/usr/local/include/node/node_internals.h
/usr/local/include/node/node_buffer.h
/usr/local/include/node/node.h
/usr/local/include/node/nameser.h
/usr/local/include/node/config.gypi
/usr/local/include/node/common.gypi
/usr/local/include/node/ares_version.h
/usr/local/include/node/ares.h
/usr/local/share/man/man1/node.1
/usr/local/lib/dtrace/node.d
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Summary
  /usr/local/Cellar/node/0.10.26: 1523 files, 18M
christohersmbp3:angular-phonecat christopherspears$ brew link node
Linking /usr/local/Cellar/node/0.10.26... 
Error: Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
  rm /usr/local/bin/node

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
christohersmbp3:angular-phonecat christopherspears$ brew link --overwrite node
Linking /usr/local/Cellar/node/0.10.26... 135 symlinks created
christohersmbp3:angular-phonecat christopherspears$ brew postinstall node
Error: Permission denied - /usr/local/lib/node_modules/npm/AUTHORS

我查看了文件夹:

christohersmbp3:npm christopherspears$ pwd
/usr/local/lib/node_modules/npm
christohersmbp3:npm christopherspears$ ll
total 112
-rw-r--r--   1 24561              staff  5759 Feb 18 14:59 AUTHORS
-rw-rw-r--   1 24561              staff   380 Feb 18 14:59 CONTRIBUTING.md
-rw-r--r--   1 24561              staff  9862 Feb 18 14:59 LICENSE
-rw-r--r--   1 24561              staff  6178 Jan 28 19:21 Makefile
-rw-r--r--   1 24561              staff  7623 Feb 18 14:59 README.md
drwxr-xr-x   7 christopherspears  staff   238 Apr  6 15:54 bin/
-rwxr-xr-x   1 24561              staff    48 Jan 28 19:21 cli.js*
-rwxr-xr-x   1 24561              staff   521 Jan 28 19:21 configure*
drwxr-xr-x   6 christopherspears  staff   204 Mar  7 22:32 doc/
drwxr-xr-x   9 christopherspears  staff   306 Apr  6 15:54 html/
drwxr-xr-x  55 christopherspears  staff  1870 Apr  6 15:54 lib/
-rw-rw-r--   1 24561              staff   156 Jan 28 19:21 make.bat
drwxr-xr-x   6 christopherspears  staff   204 Mar  7 22:32 man/
drwxr-xr-x  51 christopherspears  staff  1734 Mar  7 22:32 node_modules/
-rw-r--r--   1 24561              staff  3449 Feb 18 14:59 package.json
drwxr-xr-x   8 christopherspears  staff   272 Apr  6 15:54 scripts/
drwxr-xr-x   9 24561              staff   306 Apr  6 15:54 test/

我应该将所有者从24561更改为christopherspears吗?

更新:

我已将AUTHORS文件的所有者更改为christopherspears。现在我遇到了这个错误:

christohersmbp3:angular-phonecat christopherspears$ brew postinstall node
Error: Permission denied - /usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp

看起来是相同的问题:

christohersmbp3:node-gyp-bin christopherspears$ ll
total 16
-rwxr-xr-x  1 24561  staff  89 Jan 28 19:21 node-gyp*
-rwxr-xr-x  1 24561  staff  61 Jan 28 19:21 node-gyp.cmd*

我需要为所有由24561拥有的文件做这个吗?希望不需要。

更新:

唉,太糟糕了。看起来我被要求在所有地方将所有者从24561更改为我的用户名。为什么一开始会将所有者设置为24561呢?

1个回答

3

将所有者从24561更改为我的用户名后,我成功运行了npm。


更改什么的所有者?具体是哪个目录? - Vincil Bishop
我想我刚刚更改了每个所有者设置为24561的目录的所有者。 - Christopher Spears
6
通常在一些地方会看到这样的建议:$ sudo chown -R YourUserName /usr/local/lib/node_modules/ - 7stud

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接