我今天一直在努力解决这个问题,并且无法弄清问题是什么 - 不幸的是谷歌没有多大帮助。
我试图关注AngularJS教程,但无法安装Karma。每次我尝试时都会收到错误说"错误检索当前目录:getcwd:无法访问父目录:Permission denied"。
这是bash中输出的副本:
Barts-MacBook-Pro:~ bart$ sudo npm install -g karma
Password:
npm http GET https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/karma
npm http 200 https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/karma/-/karma-0.8.5.tgz
npm http 200 https://registry.npmjs.org/karma/-/karma-0.8.5.tgz
npm http GET https://registry.npmjs.org/chokidar
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/xmlbuilder/0.4.2
npm http GET https://registry.npmjs.org/optimist/0.3.5
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/LiveScript/1.0.1
npm http GET https://registry.npmjs.org/dateformat/1.0.2-1.2.3
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/istanbul/0.1.22
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/growly
npm http GET https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/log4js
npm http GET https://registry.npmjs.org/http-proxy
npm http 304 https://registry.npmjs.org/chokidar
npm http 304 https://registry.npmjs.org/xmlbuilder/0.4.2
npm http 200 https://registry.npmjs.org/optimist/0.3.5
npm http GET https://registry.npmjs.org/optimist/-/optimist-0.3.5.tgz
npm http 200 https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/colors/-/colors-0.6.0-1.tgz
npm http 304 https://registry.npmjs.org/LiveScript/1.0.1
npm http 304 https://registry.npmjs.org/dateformat/1.0.2-1.2.3
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/rimraf
npm http 200 https://registry.npmjs.org/coffee-script
npm http 200 https://registry.npmjs.org/colors/-/colors-0.6.0-1.tgz
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/growly
npm http 304 https://registry.npmjs.org/istanbul/0.1.22
npm http 200 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/minimatch/-/minimatch-0.2.12.tgz
npm http 304 https://registry.npmjs.org/log4js
npm http 200 https://registry.npmjs.org/optimist/-/optimist-0.3.5.tgz
npm http 200 https://registry.npmjs.org/minimatch/-/minimatch-0.2.12.tgz
npm http 200 https://registry.npmjs.org/glob
npm http 200 https://registry.npmjs.org/socket.io
npm http 200 https://registry.npmjs.org/http-proxy
npm http GET https://registry.npmjs.org/http-proxy/-/http-proxy-0.10.2.tgz
npm http 200 https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/q/-/q-0.9.3.tgz
npm http 200 https://registry.npmjs.org/lodash
npm http 200 https://registry.npmjs.org/http-proxy/-/http-proxy-0.10.2.tgz
npm http 200 https://registry.npmjs.org/q/-/q-0.9.3.tgz
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/socket.io-client/0.9.11
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/base64id/0.1.0
npm http GET https://registry.npmjs.org/redis/0.7.3
npm http GET https://registry.npmjs.org/prelude-ls
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/dequeue/1.0.3
npm http GET https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/readable-stream
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/handlebars
npm http GET https://registry.npmjs.org/escodegen
npm http GET https://registry.npmjs.org/fileset
npm http GET https://registry.npmjs.org/which
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/pkginfo
npm http GET https://registry.npmjs.org/utile
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.11
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/base64id/0.1.0
npm http 304 https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/prelude-ls
npm http 304 https://registry.npmjs.org/dequeue/1.0.3
npm http 200 https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/async/-/async-0.1.15.tgz
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http GET https://registry.npmjs.org/ws
npm http 304 https://registry.npmjs.org/semver
npm http 304 https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/esprima
npm http 200 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/handlebars
npm http 304 https://registry.npmjs.org/fileset
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/pkginfo
npm http 304 https://registry.npmjs.org/which
npm http 304 https://registry.npmjs.org/utile
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/deep-equal
npm http GET https://registry.npmjs.org/i
npm http GET https://registry.npmjs.org/ncp
npm http 200 https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-1.2.5.tgz
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http 200 https://registry.npmjs.org/async/-/async-0.1.15.tgz
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/deep-equal
npm http 304 https://registry.npmjs.org/i
npm http 304 https://registry.npmjs.org/ncp
npm http 200 https://registry.npmjs.org/escodegen
npm http GET https://registry.npmjs.org/escodegen/-/escodegen-0.0.21.tgz
npm http 200 https://registry.npmjs.org/ws
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-1.2.5.tgz
npm http 200 https://registry.npmjs.org/escodegen/-/escodegen-0.0.21.tgz
npm http 200 https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/estraverse
npm http GET https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/uglify-js
npm http 304 https://registry.npmjs.org/source-map
npm http 304 https://registry.npmjs.org/estraverse
npm http 304 https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/amdefine
npm http 200 https://registry.npmjs.org/uglify-js
npm http 304 https://registry.npmjs.org/amdefine
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/tinycolor
npm http 304 https://registry.npmjs.org/options
npm http 200 https://registry.npmjs.org/commander
> ws@0.4.25 install /usr/local/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
/usr/local/bin/karma -> /usr/local/lib/node_modules/karma/bin/karma
karma@0.8.5 /usr/local/lib/node_modules/karma
├── pause@0.0.1
├── dateformat@1.0.2-1.2.3
├── xmlbuilder@0.4.2
├── colors@0.6.0-1
├── chokidar@0.6.2
├── growly@1.1.1
├── mime@1.2.9
├── q@0.9.3
├── coffee-script@1.6.2
├── lodash@1.1.1
├── glob@3.1.21 (inherits@1.0.0, graceful-fs@1.2.0)
├── rimraf@2.1.4 (graceful-fs@1.2.0)
├── optimist@0.3.5 (wordwrap@0.0.2)
├── LiveScript@1.0.1 (prelude-ls@0.6.0)
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.3.0)
├── log4js@0.6.3 (dequeue@1.0.3, semver@1.1.4, async@0.1.15, readable-stream@1.0.2)
├── http-proxy@0.10.2 (pkginfo@0.2.3, utile@0.1.7)
├── istanbul@0.1.22 (abbrev@1.0.4, which@1.0.5, fileset@0.1.5, nopt@2.0.0, wordwrap@0.0.2, async@0.1.22, mkdirp@0.3.5, esprima@0.9.9, handlebars@1.0.10, escodegen@0.0.21)
└── socket.io@0.9.14 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.11)
Barts-MacBook-Pro:~ bart$
我正在运行Node 0.10.4,顺便说一句。
不幸的是,我现在有点亏,所以任何帮助都会感激不尽!
非常感谢,
巴特
编辑 - 2017年1月
我最初问过这个问题w.r.t. OSX Mountain Lion,但我也在较新版本的OSX上遇到过类似的问题。我在下面编辑了我的答案,包括我认为对于所有版本的OSX更好的解决方案。
答案 0 :(得分:6)
好的,所以我进一步深入研究了这一点,并尝试了以下内容:
sudo npm install -g ws
这是实际无法安装的软件包。从那里谷歌搜索在StackOverflow上找到了这个:Trouble installing tower module - ws module crashes。这导致我在Macbook Pro上启用root帐户的说明:http://support.apple.com/kb/ht1528。
一旦我完成了,我现在可以在bash中执行以下命令以成功安装业力:
su
npm install -g karma
就是这样!希望这可以帮助遇到类似问题的其他人。
编辑 - 2017年1月 - 更好的解决方案
为了避免在OSX上使用sudo安装全局模块的整个戏剧,这可能导致奇怪的问题,例如getcwd()由于缺乏权限而失败,我强烈建议使用nvm安装节点:{{3 }}。这样做的另一个好处是,您还可以在同一台计算机上使用多个版本的节点。