在Ubuntu全局安装express报错:Error: EACCES, mkdir '/usr/lib/node_modules/express'的解决办法
$ npm install -g express npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/express' npm ERR! { [Error: EACCES, mkdir '/usr/lib/node_modules/express'] npm ERR! errno: 3, npm ERR! code: 'EACCES', npm ERR! path: '/usr/lib/node_modules/express', npm ERR! fstream_type: 'Directory', npm ERR! fstream_path: '/usr/lib/node_modules/express', npm ERR! fstream_class: 'DirWriter', npm ERR! fstream_stack: npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23', npm ERR! '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53', npm ERR! 'Object.oncomplete (fs.js:108:15)' ] } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! System Linux 4.4.0-31-generic npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "express" npm ERR! cwd /home/zmj97 npm ERR! node -v v0.10.37 npm ERR! npm -v 1.4.28 npm ERR! path /usr/lib/node_modules/express npm ERR! fstream_path /usr/lib/node_modules/express npm ERR! fstream_type Directory npm ERR! fstream_class DirWriter npm ERR! code EACCES npm ERR! errno 3 npm ERR! stack Error: EACCES, mkdir '/usr/lib/node_modules/express' npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23 npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53 npm ERR! fstream_stack Object.oncomplete (fs.js:108:15) npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /home/zmj97/npm-debug.log npm ERR! not ok code 0
在全局安装时报错,提示“Please try running this command again as root/Administrator.”,
加上sudo即可。
$ sudo npm install -g express [sudo] password for zmj97: express@4.14.0 /usr/lib/node_modules/express ├── escape-html@1.0.3 ├── array-flatten@1.1.1 ├── utils-merge@1.0.0 ├── cookie-signature@1.0.6 ├── merge-descriptors@1.0.1 ├── fresh@0.3.0 ├── methods@1.1.2 ├── path-to-regexp@0.1.7 ├── vary@1.1.0 ├── encodeurl@1.0.1 ├── range-parser@1.2.0 ├── parseurl@1.3.1 ├── etag@1.7.0 ├── content-type@1.0.2 ├── cookie@0.3.1 ├── content-disposition@0.5.1 ├── serve-static@1.11.1 ├── depd@1.1.0 ├── qs@6.2.0 ├── on-finished@2.3.0 (ee-first@1.1.1) ├── debug@2.2.0 (ms@0.7.1) ├── finalhandler@0.5.0 (unpipe@1.0.0, statuses@1.3.1) ├── proxy-addr@1.1.2 (forwarded@0.1.0, ipaddr.js@1.1.1) ├── type-is@1.6.14 (media-typer@0.3.0, mime-types@2.1.13) ├── accepts@1.3.3 (negotiator@0.6.1, mime-types@2.1.13) └── send@0.14.1 (destroy@1.0.4, ms@0.7.1, mime@1.3.4, statuses@1.3.1, http-errors@1.5.1)
安装成功!
查看已安装包中包括express:
$ npm ls -g /usr/lib ├─┬ express@4.14.0 │ ├─┬ accepts@1.3.3 │ │ ├─┬ mime-types@2.1.13 │ │ │ └── mime-db@1.25.0 │ │ └── negotiator@0.6.1 │ ├── array-flatten@1.1.1 │ ├── content-disposition@0.5.1 │ ├── content-type@1.0.2 │ ├── cookie@0.3.1 │ ├── cookie-signature@1.0.6 │ ├─┬ debug@2.2.0 │ │ └── ms@0.7.1 │ ├── depd@1.1.0 │ ├── encodeurl@1.0.1 │ ├── escape-html@1.0.3 │ ├── etag@1.7.0 │ ├─┬ finalhandler@0.5.0 │ │ ├── statuses@1.3.1 │ │ └── unpipe@1.0.0 │ ├── fresh@0.3.0 │ ├── merge-descriptors@1.0.1 │ ├── methods@1.1.2 │ ├─┬ on-finished@2.3.0 │ │ └── ee-first@1.1.1 │ ├── parseurl@1.3.1 │ ├── path-to-regexp@0.1.7 │ ├─┬ proxy-addr@1.1.2 │ │ ├── forwarded@0.1.0 │ │ └── ipaddr.js@1.1.1 │ ├── qs@6.2.0 │ ├── range-parser@1.2.0 │ ├─┬ send@0.14.1 │ │ ├── destroy@1.0.4 │ │ ├─┬ http-errors@1.5.1 │ │ │ ├── inherits@2.0.3 │ │ │ └── setprototypeof@1.0.2 │ │ ├── mime@1.3.4 │ │ ├── ms@0.7.1 │ │ └── statuses@1.3.1 │ ├── serve-static@1.11.1 │ ├─┬ type-is@1.6.14 │ │ ├── media-typer@0.3.0 │ │ └─┬ mime-types@2.1.13 │ │ └── mime-db@1.25.0 │ ├── utils-merge@1.0.0 │ └── vary@1.1.0