如何将 npm 包安装到当前工作目录?
How to install npm packages to current working directory?
我想将 coffee-script 安装到我当前的工作目录。因此我 运行:
npm install coffee-script
不幸的是抛出了一个错误
npm ERR! Error: EACCES, symlink '../coffee-script/bin/coffee'
npm ERR! { [Error: EACCES, symlink '../coffee-script/bin/coffee'] errno: 3, code: 'EACCES', path: '../coffee-script/bin/coffee' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.16.0-30-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "coffee-script"
npm ERR! cwd /home/username/git/project
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.4.21
npm ERR! path ../coffee-script/bin/coffee
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../coffee-script/bin/coffee'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/username/git/project/npm-debug.log
npm ERR! not ok code 0
我不明白,为什么我必须 运行 npm
作为管理员,因为我不想全局安装它,...
当我 运行 sudo npm install coffee-script
时,coffee-script 安装到我的主目录 (~/node_modules/coffee-script
) 而不是当前工作目录。
我从 Ubuntu 14.10 存储库安装了 npm
。另外我安装了包 nodejs-legacy
.
npm-debug.log
的输出是:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'install', 'coffee-script' ]
2 info using npm@1.4.21
3 info using node@v0.10.25
4 verbose config Skipping project config: /home/username/.npmrc. (matches userconfig)
5 verbose cache add [ 'coffee-script', null ]
6 verbose cache add name=undefined spec="coffee-script" args=["coffee-script",null]
7 verbose parsed url { protocol: null,
7 verbose parsed url slashes: null,
7 verbose parsed url auth: null,
7 verbose parsed url host: null,
7 verbose parsed url port: null,
7 verbose parsed url hostname: null,
7 verbose parsed url hash: null,
7 verbose parsed url search: null,
7 verbose parsed url query: null,
7 verbose parsed url pathname: 'coffee-script',
7 verbose parsed url path: 'coffee-script',
7 verbose parsed url href: 'coffee-script' }
8 silly lockFile ab358269-coffee-script coffee-script
9 verbose lock coffee-script /home/username/.npm/ab358269-coffee-script.lock
10 silly lockFile ab358269-coffee-script coffee-script
11 silly lockFile ab358269-coffee-script coffee-script
12 verbose addNamed [ 'coffee-script', '' ]
13 verbose addNamed [ null, '*' ]
14 silly lockFile 53951495-coffee-script coffee-script@
15 verbose lock coffee-script@ /home/username/.npm/53951495-coffee-script.lock
16 silly addNameRange { name: 'coffee-script', range: '*', hasData: false }
17 verbose request where is /coffee-script
18 verbose request registry https://registry.npmjs.org/
19 verbose request id abb6339315a81c84
20 verbose url raw /coffee-script
21 verbose url resolving [ 'https://registry.npmjs.org/', './coffee-script' ]
22 verbose url resolved https://registry.npmjs.org/coffee-script
23 verbose request where is https://registry.npmjs.org/coffee-script
24 info trying registry request attempt 1 at 14:39:35
25 verbose etag "C6XKWMKZT8HLZEMOMC3EPHFEX"
26 http GET https://registry.npmjs.org/coffee-script
27 http 304 https://registry.npmjs.org/coffee-script
28 silly registry.get cb [ 304,
28 silly registry.get { date: 'Thu, 12 Feb 2015 13:39:36 GMT',
28 silly registry.get server: 'Apache',
28 silly registry.get via: '1.1 varnish',
28 silly registry.get 'last-modified': 'Thu, 12 Feb 2015 12:59:26 GMT',
28 silly registry.get 'cache-control': 'max-age=60',
28 silly registry.get etag: '"C6XKWMKZT8HLZEMOMC3EPHFEX"',
28 silly registry.get age: '54',
28 silly registry.get 'x-served-by': 'cache-lcy1123-LCY',
28 silly registry.get 'x-cache': 'HIT',
28 silly registry.get 'x-cache-hits': '450',
28 silly registry.get 'x-timer': 'S1423748376.054272,VS0,VE0',
28 silly registry.get vary: 'Accept',
28 silly registry.get 'content-length': '0',
28 silly registry.get 'keep-alive': 'timeout=10, max=50',
28 silly registry.get connection: 'Keep-Alive' } ]
29 verbose etag https://registry.npmjs.org/coffee-script from cache
30 silly addNameRange number 2 { name: 'coffee-script', range: '*', hasData: true }
31 silly addNameRange versions [ 'coffee-script',
31 silly addNameRange [ '0.7.0',
31 silly addNameRange '0.7.1',
31 silly addNameRange '0.7.2',
31 silly addNameRange '0.9.0',
31 silly addNameRange '0.9.1',
31 silly addNameRange '0.9.2',
31 silly addNameRange '0.9.3',
31 silly addNameRange '0.9.4',
31 silly addNameRange '0.9.5',
31 silly addNameRange '0.9.6',
31 silly addNameRange '1.0.0',
31 silly addNameRange '1.0.1',
31 silly addNameRange '1.1.0',
31 silly addNameRange '1.1.1',
31 silly addNameRange '1.1.2',
31 silly addNameRange '1.1.3',
31 silly addNameRange '1.2.0',
31 silly addNameRange '1.3.0',
31 silly addNameRange '1.3.1',
31 silly addNameRange '1.3.2',
31 silly addNameRange '1.3.3',
31 silly addNameRange '1.4.0',
31 silly addNameRange '1.5.0',
31 silly addNameRange '1.6.0',
31 silly addNameRange '1.6.1',
31 silly addNameRange '1.6.2',
31 silly addNameRange '1.6.3',
31 silly addNameRange '1.7.0',
31 silly addNameRange '1.7.1',
31 silly addNameRange '1.8.0',
31 silly addNameRange '1.9.0' ] ]
32 verbose addNamed [ 'coffee-script', '1.9.0' ]
33 verbose addNamed [ '1.9.0', '1.9.0' ]
34 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
35 verbose lock coffee-script@1.9.0 /home/username/.npm/479ea950-coffee-script-1-9-0.lock
36 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
37 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
38 silly lockFile 53951495-coffee-script coffee-script@
39 silly lockFile 53951495-coffee-script coffee-script@
40 silly resolved [ { name: 'coffee-script',
40 silly resolved description: 'Unfancy JavaScript',
40 silly resolved keywords: [ 'javascript', 'language', 'coffeescript', 'compiler' ],
40 silly resolved author: { name: 'Jeremy Ashkenas' },
40 silly resolved version: '1.9.0',
40 silly resolved license: 'MIT',
40 silly resolved engines: { node: '>=0.8.0' },
40 silly resolved directories: { lib: './lib/coffee-script' },
40 silly resolved main: './lib/coffee-script/coffee-script',
40 silly resolved bin: { coffee: './bin/coffee', cake: './bin/cake' },
40 silly resolved preferGlobal: true,
40 silly resolved scripts:
40 silly resolved { test: 'node ./bin/cake test',
40 silly resolved 'test-harmony': 'node --harmony ./bin/cake test' },
40 silly resolved homepage: 'http://coffeescript.org',
40 silly resolved bugs: { url: 'https://github.com/jashkenas/coffeescript/issues' },
40 silly resolved repository:
40 silly resolved { type: 'git',
40 silly resolved url: 'git://github.com/jashkenas/coffeescript.git' },
40 silly resolved devDependencies:
40 silly resolved { 'uglify-js': '~2.2',
40 silly resolved jison: '>=0.2.0',
40 silly resolved 'highlight.js': '~8.0.0',
40 silly resolved underscore: '~1.5.2',
40 silly resolved docco: '~0.6.2' },
40 silly resolved gitHead: 'f7692c92ce61c277a3f9a38c6bdbe712730d040a',
40 silly resolved _id: 'coffee-script@1.9.0',
40 silly resolved _shasum: '7492cbbc3f0361cc5d8865aff7237552ff33e1f7',
40 silly resolved _from: 'coffee-script@',
40 silly resolved _npmVersion: '1.4.28',
40 silly resolved _npmUser: { name: 'jashkenas', email: 'jashkenas@gmail.com' },
40 silly resolved maintainers: [ [Object], [Object] ],
40 silly resolved dist:
40 silly resolved { shasum: '7492cbbc3f0361cc5d8865aff7237552ff33e1f7',
40 silly resolved tarball: 'http://registry.npmjs.org/coffee-script/-/coffee-script-1.9.0.tgz' },
40 silly resolved _resolved: 'https://registry.npmjs.org/coffee-script/-/coffee-script-1.9.0.tgz',
40 silly resolved readme: 'ERROR: No README data found!' } ]
41 info install coffee-script@1.9.0 into /home/username
42 info installOne coffee-script@1.9.0
43 verbose node_modules/coffee-script unbuild
44 info preuninstall coffee-script@1.9.0
45 info uninstall coffee-script@1.9.0
46 verbose true,/home/username/node_modules,/home/username/node_modules unbuild coffee-script@1.9.0
47 verbose /home/username/node_modules/.bin,[object Object] binRoot
48 verbose node_modules/coffee-script unbuild
49 info preuninstall coffee-script@1.9.0
50 info uninstall coffee-script@1.9.0
51 verbose true,/home/username/node_modules,/home/username/node_modules unbuild coffee-script@1.9.0
52 verbose /home/username/node_modules/.bin,[object Object] binRoot
53 error error rolling back Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
53 error error rolling back coffee-script@1.9.0 { [Error: EACCES, unlink '/home/username/node_modules/.bin/coffee']
53 error error rolling back errno: 3,
53 error error rolling back code: 'EACCES',
53 error error rolling back path: '/home/username/node_modules/.bin/coffee' }
54 error Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
54 error { [Error: EACCES, unlink '/home/username/node_modules/.bin/coffee']
54 error errno: 3,
54 error code: 'EACCES',
54 error path: '/home/username/node_modules/.bin/coffee' }
55 error Please try running this command again as root/Administrator.
56 error System Linux 3.16.0-30-generic
57 error command "/usr/bin/nodejs" "/usr/bin/npm" "install" "coffee-script"
58 error cwd /home/username/Desktop/npmtest
59 error node -v v0.10.25
60 error npm -v 1.4.21
61 error path /home/username/node_modules/.bin/coffee
62 error code EACCES
63 error errno 3
64 error stack Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
65 verbose exit [ 3, true ]
先试一下
install nmp cache clean
及之后
npm install coffee-script
尝试将您的 npm
更新到更新的版本:
[sudo] npm install -g npm
并再次安装 coffee-script 模块。
此外,请确保您的 ~/.npmrc
文件中没有设置 global: true
。
我想将 coffee-script 安装到我当前的工作目录。因此我 运行:
npm install coffee-script
不幸的是抛出了一个错误
npm ERR! Error: EACCES, symlink '../coffee-script/bin/coffee'
npm ERR! { [Error: EACCES, symlink '../coffee-script/bin/coffee'] errno: 3, code: 'EACCES', path: '../coffee-script/bin/coffee' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.16.0-30-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "coffee-script"
npm ERR! cwd /home/username/git/project
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.4.21
npm ERR! path ../coffee-script/bin/coffee
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../coffee-script/bin/coffee'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/username/git/project/npm-debug.log
npm ERR! not ok code 0
我不明白,为什么我必须 运行 npm
作为管理员,因为我不想全局安装它,...
当我 运行 sudo npm install coffee-script
时,coffee-script 安装到我的主目录 (~/node_modules/coffee-script
) 而不是当前工作目录。
我从 Ubuntu 14.10 存储库安装了 npm
。另外我安装了包 nodejs-legacy
.
npm-debug.log
的输出是:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'install', 'coffee-script' ]
2 info using npm@1.4.21
3 info using node@v0.10.25
4 verbose config Skipping project config: /home/username/.npmrc. (matches userconfig)
5 verbose cache add [ 'coffee-script', null ]
6 verbose cache add name=undefined spec="coffee-script" args=["coffee-script",null]
7 verbose parsed url { protocol: null,
7 verbose parsed url slashes: null,
7 verbose parsed url auth: null,
7 verbose parsed url host: null,
7 verbose parsed url port: null,
7 verbose parsed url hostname: null,
7 verbose parsed url hash: null,
7 verbose parsed url search: null,
7 verbose parsed url query: null,
7 verbose parsed url pathname: 'coffee-script',
7 verbose parsed url path: 'coffee-script',
7 verbose parsed url href: 'coffee-script' }
8 silly lockFile ab358269-coffee-script coffee-script
9 verbose lock coffee-script /home/username/.npm/ab358269-coffee-script.lock
10 silly lockFile ab358269-coffee-script coffee-script
11 silly lockFile ab358269-coffee-script coffee-script
12 verbose addNamed [ 'coffee-script', '' ]
13 verbose addNamed [ null, '*' ]
14 silly lockFile 53951495-coffee-script coffee-script@
15 verbose lock coffee-script@ /home/username/.npm/53951495-coffee-script.lock
16 silly addNameRange { name: 'coffee-script', range: '*', hasData: false }
17 verbose request where is /coffee-script
18 verbose request registry https://registry.npmjs.org/
19 verbose request id abb6339315a81c84
20 verbose url raw /coffee-script
21 verbose url resolving [ 'https://registry.npmjs.org/', './coffee-script' ]
22 verbose url resolved https://registry.npmjs.org/coffee-script
23 verbose request where is https://registry.npmjs.org/coffee-script
24 info trying registry request attempt 1 at 14:39:35
25 verbose etag "C6XKWMKZT8HLZEMOMC3EPHFEX"
26 http GET https://registry.npmjs.org/coffee-script
27 http 304 https://registry.npmjs.org/coffee-script
28 silly registry.get cb [ 304,
28 silly registry.get { date: 'Thu, 12 Feb 2015 13:39:36 GMT',
28 silly registry.get server: 'Apache',
28 silly registry.get via: '1.1 varnish',
28 silly registry.get 'last-modified': 'Thu, 12 Feb 2015 12:59:26 GMT',
28 silly registry.get 'cache-control': 'max-age=60',
28 silly registry.get etag: '"C6XKWMKZT8HLZEMOMC3EPHFEX"',
28 silly registry.get age: '54',
28 silly registry.get 'x-served-by': 'cache-lcy1123-LCY',
28 silly registry.get 'x-cache': 'HIT',
28 silly registry.get 'x-cache-hits': '450',
28 silly registry.get 'x-timer': 'S1423748376.054272,VS0,VE0',
28 silly registry.get vary: 'Accept',
28 silly registry.get 'content-length': '0',
28 silly registry.get 'keep-alive': 'timeout=10, max=50',
28 silly registry.get connection: 'Keep-Alive' } ]
29 verbose etag https://registry.npmjs.org/coffee-script from cache
30 silly addNameRange number 2 { name: 'coffee-script', range: '*', hasData: true }
31 silly addNameRange versions [ 'coffee-script',
31 silly addNameRange [ '0.7.0',
31 silly addNameRange '0.7.1',
31 silly addNameRange '0.7.2',
31 silly addNameRange '0.9.0',
31 silly addNameRange '0.9.1',
31 silly addNameRange '0.9.2',
31 silly addNameRange '0.9.3',
31 silly addNameRange '0.9.4',
31 silly addNameRange '0.9.5',
31 silly addNameRange '0.9.6',
31 silly addNameRange '1.0.0',
31 silly addNameRange '1.0.1',
31 silly addNameRange '1.1.0',
31 silly addNameRange '1.1.1',
31 silly addNameRange '1.1.2',
31 silly addNameRange '1.1.3',
31 silly addNameRange '1.2.0',
31 silly addNameRange '1.3.0',
31 silly addNameRange '1.3.1',
31 silly addNameRange '1.3.2',
31 silly addNameRange '1.3.3',
31 silly addNameRange '1.4.0',
31 silly addNameRange '1.5.0',
31 silly addNameRange '1.6.0',
31 silly addNameRange '1.6.1',
31 silly addNameRange '1.6.2',
31 silly addNameRange '1.6.3',
31 silly addNameRange '1.7.0',
31 silly addNameRange '1.7.1',
31 silly addNameRange '1.8.0',
31 silly addNameRange '1.9.0' ] ]
32 verbose addNamed [ 'coffee-script', '1.9.0' ]
33 verbose addNamed [ '1.9.0', '1.9.0' ]
34 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
35 verbose lock coffee-script@1.9.0 /home/username/.npm/479ea950-coffee-script-1-9-0.lock
36 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
37 silly lockFile 479ea950-coffee-script-1-9-0 coffee-script@1.9.0
38 silly lockFile 53951495-coffee-script coffee-script@
39 silly lockFile 53951495-coffee-script coffee-script@
40 silly resolved [ { name: 'coffee-script',
40 silly resolved description: 'Unfancy JavaScript',
40 silly resolved keywords: [ 'javascript', 'language', 'coffeescript', 'compiler' ],
40 silly resolved author: { name: 'Jeremy Ashkenas' },
40 silly resolved version: '1.9.0',
40 silly resolved license: 'MIT',
40 silly resolved engines: { node: '>=0.8.0' },
40 silly resolved directories: { lib: './lib/coffee-script' },
40 silly resolved main: './lib/coffee-script/coffee-script',
40 silly resolved bin: { coffee: './bin/coffee', cake: './bin/cake' },
40 silly resolved preferGlobal: true,
40 silly resolved scripts:
40 silly resolved { test: 'node ./bin/cake test',
40 silly resolved 'test-harmony': 'node --harmony ./bin/cake test' },
40 silly resolved homepage: 'http://coffeescript.org',
40 silly resolved bugs: { url: 'https://github.com/jashkenas/coffeescript/issues' },
40 silly resolved repository:
40 silly resolved { type: 'git',
40 silly resolved url: 'git://github.com/jashkenas/coffeescript.git' },
40 silly resolved devDependencies:
40 silly resolved { 'uglify-js': '~2.2',
40 silly resolved jison: '>=0.2.0',
40 silly resolved 'highlight.js': '~8.0.0',
40 silly resolved underscore: '~1.5.2',
40 silly resolved docco: '~0.6.2' },
40 silly resolved gitHead: 'f7692c92ce61c277a3f9a38c6bdbe712730d040a',
40 silly resolved _id: 'coffee-script@1.9.0',
40 silly resolved _shasum: '7492cbbc3f0361cc5d8865aff7237552ff33e1f7',
40 silly resolved _from: 'coffee-script@',
40 silly resolved _npmVersion: '1.4.28',
40 silly resolved _npmUser: { name: 'jashkenas', email: 'jashkenas@gmail.com' },
40 silly resolved maintainers: [ [Object], [Object] ],
40 silly resolved dist:
40 silly resolved { shasum: '7492cbbc3f0361cc5d8865aff7237552ff33e1f7',
40 silly resolved tarball: 'http://registry.npmjs.org/coffee-script/-/coffee-script-1.9.0.tgz' },
40 silly resolved _resolved: 'https://registry.npmjs.org/coffee-script/-/coffee-script-1.9.0.tgz',
40 silly resolved readme: 'ERROR: No README data found!' } ]
41 info install coffee-script@1.9.0 into /home/username
42 info installOne coffee-script@1.9.0
43 verbose node_modules/coffee-script unbuild
44 info preuninstall coffee-script@1.9.0
45 info uninstall coffee-script@1.9.0
46 verbose true,/home/username/node_modules,/home/username/node_modules unbuild coffee-script@1.9.0
47 verbose /home/username/node_modules/.bin,[object Object] binRoot
48 verbose node_modules/coffee-script unbuild
49 info preuninstall coffee-script@1.9.0
50 info uninstall coffee-script@1.9.0
51 verbose true,/home/username/node_modules,/home/username/node_modules unbuild coffee-script@1.9.0
52 verbose /home/username/node_modules/.bin,[object Object] binRoot
53 error error rolling back Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
53 error error rolling back coffee-script@1.9.0 { [Error: EACCES, unlink '/home/username/node_modules/.bin/coffee']
53 error error rolling back errno: 3,
53 error error rolling back code: 'EACCES',
53 error error rolling back path: '/home/username/node_modules/.bin/coffee' }
54 error Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
54 error { [Error: EACCES, unlink '/home/username/node_modules/.bin/coffee']
54 error errno: 3,
54 error code: 'EACCES',
54 error path: '/home/username/node_modules/.bin/coffee' }
55 error Please try running this command again as root/Administrator.
56 error System Linux 3.16.0-30-generic
57 error command "/usr/bin/nodejs" "/usr/bin/npm" "install" "coffee-script"
58 error cwd /home/username/Desktop/npmtest
59 error node -v v0.10.25
60 error npm -v 1.4.21
61 error path /home/username/node_modules/.bin/coffee
62 error code EACCES
63 error errno 3
64 error stack Error: EACCES, unlink '/home/username/node_modules/.bin/coffee'
65 verbose exit [ 3, true ]
先试一下
install nmp cache clean
及之后
npm install coffee-script
尝试将您的 npm
更新到更新的版本:
[sudo] npm install -g npm
并再次安装 coffee-script 模块。
此外,请确保您的 ~/.npmrc
文件中没有设置 global: true
。