我正在尝试在最新的 Ubuntu 上更新我的 Node 和 npm 版本,但我遇到了问题。我尝试了在互联网上找到的所有解决方案 — 更改权限、完全卸载并重新安装 — 但仍然不起作用。有什么建议可以解决这个问题吗?
MYUSER@MYUSER-VirtualBox:~$ npm update -g
npm WARN optional dep failed, continuing [email protected]
npm ERR! Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/init- package-json/node_modules/semver'
npm ERR! { [Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver',
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 3.16.0-33-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/MYUSER
npm ERR! node -v v0.10.38
npm ERR! npm -v 1.4.28
npm ERR! path /home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver
npm ERR! fstream_path /home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/init-package-json/node_modules/semver'
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! error rolling back Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/dezalgo/node_modules/asap'
npm ERR! error rolling back { [Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/dezalgo/node_modules/asap']
npm ERR! error rolling back errno: 3,
npm ERR! error rolling back code: 'EACCES',
npm ERR! error rolling back path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/dezalgo/node_modules/asap' }
npm ERR! Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar'
npm ERR! { [Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar',
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 3.16.0-33-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/MYUSER
npm ERR! node -v v0.10.38
npm ERR! npm -v 1.4.28
npm ERR! path /home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar
npm ERR! fstream_path /home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/tar'
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! Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request'
npm ERR! { [Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request',
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 3.16.0-33-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/MYUSER
npm ERR! node -v v0.10.38
npm ERR! npm -v 1.4.28
npm ERR! path /home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request
npm ERR! fstream_path /home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/node-gyp/node_modules/request'
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! error rolling back Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/tar'
npm ERR! error rolling back { [Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/tar']
npm ERR! error rolling back errno: 3,
npm ERR! error rolling back code: 'EACCES',
npm ERR! error rolling back path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/tar' }
npm ERR! error rolling back Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex'
npm ERR! error rolling back { [Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex']
npm ERR! error rolling back errno: 3,
npm ERR! error rolling back code: 'EACCES',
npm ERR! error rolling back path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex' }
npm ERR! Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules'
npm ERR! { [Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules/semver',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/writer.js:171: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 3.16.0-33-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/MYUSER
npm ERR! node -v v0.10.38
npm ERR! npm -v 1.4.28
npm ERR! path /home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules
npm ERR! fstream_path /home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules/semver
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/normalize-package-data/node_modules'
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/writer.js:171: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! Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request'
npm ERR! { [Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request',
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 3.16.0-33-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/MYUSER
npm ERR! node -v v0.10.38
npm ERR! npm -v 1.4.28
npm ERR! path /home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request
npm ERR! fstream_path /home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/MYUSER/.node/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/request'
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! error rolling back Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/request'
npm ERR! error rolling back { [Error: EACCES, unlink '/home/MYUSER/.node/lib/node_modules/npm/node_modules/request']
npm ERR! error rolling back errno: 3,
npm ERR! error rolling back code: 'EACCES',
npm ERR! error rolling back path: '/home/MYUSER/.node/lib/node_modules/npm/node_modules/request' }
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/MYUSER/npm-debug.log
npm ERR! not ok code 0
答案1
正如我所说,我尝试过这个...它仍然返回节点和 npm 的相同版本。
我按照以下步骤彻底删除该问题并解决了它:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
You may need to do the additional instructions as well:
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
之后我从 git 安装了节点:
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install
最后重启系统解决了这个问题。不过还是谢谢你的回答。
答案2
有时仔细观察日志你会发现一些令人惊奇的事情,比如
npm ERR! Please try running this command again as root/Administrator.
这引出了我的建议,使用 sudo 重试
sudo npm update -g