npm报错解决:Error: ENOSPC, write
在Linux使用npm安装mongodb报了ENOSPC的错误,错误信息:
# npm install mongodb
npm http GET https://registry.npmjs.org/mongodb
npm http 200 https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/mongodb/-/mongodb-1.0.2.tgz
npm http 200 https://registry.npmjs.org/mongodb/-/mongodb-1.0.2.tgz
npm ERR! Error: ENOSPC, write
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Linux 2.6.33.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "mongodb"
npm ERR! cwd /root
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.21
npm ERR! code ENOSPC
npm ERR! message ENOSPC, write
npm ERR! errno {}
原因
默认情况下,Linux使用inotify来监控目录的改变,报这个错是因为超出了系统监控文件数的最大值。Ubuntu设定的最大值为8192。
解决方法
Debian,RetHat以及和这两个系统类似的操作系统,如Ubuntu和CentOS执行以下命令:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
ArchLinux则使用以下命令:
echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system