在安装Mac、Vagrant、Ubuntu和Node.js时突然遇到困难

记录下来

在Mac上通过ssh连接到Vagrant上的ubuntu,并在其上安装node.js。

vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt install -y nodejs npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
npm is already the newest version.
nodejs is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

到目前为止一切顺利。

vagrant@vagrant-ubuntu-trusty-64:~$  sudo npm install n -g
npm http GET https://registry.npmjs.org/n
npm http GET https://registry.npmjs.org/n
npm http GET https://registry.npmjs.org/n
npm ERR! Error: CERT_UNTRUSTED
npm ERR!     at SecurePair.<anonymous> (tls.js:1370:32)
npm ERR!     at SecurePair.EventEmitter.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:982:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:469:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:320:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:366:25)
npm ERR!     at doWrite (_stream_writable.js:223:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:213:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:180:11)
npm ERR!     at write (_stream_readable.js:583:24)
npm ERR! If you need help, 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! System Linux 3.13.0-165-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "n" "-g"
npm ERR! cwd /home/vagrant
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/vagrant/npm-debug.log
npm ERR! not ok code 0

发生错误并停止了。
尝试搜索“npm ERR!错误:”
似乎需要输入以下命令:npm config set strict-ssl false。
不要忘记在完成后将其恢复为true。

vagrant@vagrant-ubuntu-trusty-64:~$ npm config set strict-ssl false
vagrant@vagrant-ubuntu-trusty-64:~$
vagrant@vagrant-ubuntu-trusty-64:~$  sudo npm install n -g
npm http GET https://registry.npmjs.org/n
npm http 200 https://registry.npmjs.org/n
npm http GET https://registry.npmjs.org/n/-/n-2.1.12.tgz
npm http 200 https://registry.npmjs.org/n/-/n-2.1.12.tgz
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
n@2.1.12 /usr/local/lib/node_modules/n

只要完成这个,就可以继续前进。