npm throws a segmentation fault with Ubuntu 16.04 and Node 6.0.0

社会主义新天地 提交于 2020-12-03 17:16:12

问题


I've installed the newest version of node (6.0.0) on Ubuntu 16.04, but when I tried to install Yeoman (or any other npm module for that matter) globally, it throws out a Segmentation fault

~$ node -v
6.0.0
~$ npm -v
3.8.6
~$ sudo npm install -g yo
normalizeTree → headers   ▌ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
Segmentation fault (core dumped)
~$ sudo npm install -g npm
normalizeTree → 200       ▌ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
Segmentation fault (core dumped)

I've also tried reinstalling npm by cloning the git repository, but it failed there as well

~/Documents$ git clone https://github.com/npm/npm.git
Cloning into 'npm'...
remote: Counting objects: 55706, done.
remote: Compressing objects: 100% (158/158), done.
remote: Total 55706 (delta 64), reused 0 (delta 0), pack-reused 55547
Receiving objects: 100% (55706/55706), 29.55 MiB | 1.25 MiB/s, done.
Resolving deltas: 100% (30297/30297), done.
Checking connectivity... done.
~/Documents$ ls
npm
~/Documents$ cd npm
~/Documents/npm$ ls
AUTHORS       changelogs  CONTRIBUTING.md  lib       Makefile      README.md
bin           cli.js      doc              LICENSE   node_modules  scripts
CHANGELOG.md  configure   html             make.bat  package.json  test
~/Documents/npm$ ./configure node_debug=1
~/Documents/npm$ make
scripts/doc-build.sh doc/cli/npm-bugs.md man/man1/npm-bugs.1
make[1]: Entering directory '/home/cameron/Documents/npm'
node cli.js install marked-man --no-global
normalizeTree → install   ▌ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
Makefile:151: recipe for target 'node_modules/.bin/marked-man' failed
make[1]: *** [node_modules/.bin/marked-man] Segmentation fault (core dumped)
make[1]: Leaving directory '/home/cameron/Documents/npm'
Makefile:96: recipe for target 'man/man1/npm-bugs.1' failed
make: *** [man/man1/npm-bugs.1] Error 2
~/Documents/npm$

I've scoured Stack Overflow to find an answer, but nothing helped me. I have no idea what to try now. Any suggestions?


回答1:


For anyone else facing this issue after upgrading to ubuntu 19.04, try running:

sudo apt --auto-remove purge npm
sudo apt --auto-remove purge nodejs

It seems there must be more than one version of nodejs or npm installed on upgrade. After running the above commands, you can check nodejs and npm versions.

This fix has been posted in the npm community:

https://npm.community/t/segmentation-fault-core-dumped-error-for-every-npm-command/7086




回答2:


My first suggestion is to open an issue in the npm repo, but as of writing this it have 2,269 opened issues... my god.

I recommend to install an older version of node with nodeenv, I currently use it and works very well, in fact for me it's the way to go when working with node.js, I don't like to get hit by a backwards compatibility breakage.




回答3:


re install a new nodejs version use n.

n vx.x.x

n rm vx.x.x (remove broken verison)


来源:https://stackoverflow.com/questions/36961871/npm-throws-a-segmentation-fault-with-ubuntu-16-04-and-node-6-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!