安装nodejs

3m安装法

安装nvm

  1. $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 7766 100 7766 0 0 28614 0 --:--:-- --:--:-- --:--:-- 28656
  5. => Downloading nvm as script to '/home/sang/.nvm'
  6. => Appending source string to /home/sang/.bashrc
  7. => Close and reopen your terminal to start using nvm
  8. $ source ~/.bashrc
  9. $ nvm
  10. Node Version Manager

安装nodejs lts版本

  1. $ nvm install 4
  2. Downloading https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-x64.tar.xz...
  3. #################################### 100.0%
  4. Now using node v4.3.2 (npm v2.14.12)
  5. Creating default alias: default -> 4 (-> v4.3.2)
  6. $ node -v
  7. v4.3.2

使之成为默认

  1. $ nvm alias default 4.3
  2. default -> 4.3 (-> v4.3.2)

确认npm版本

  1. $ npm -v
  2. 2.14.12

只要大于2.9.1即可,如不是,请npm i -g npm@2.9.1

安装nrm

  1. $ npm i -g nrm
  2. npm WARN deprecated npmconf@0.1.16: this package has been reintegrated into npm and is now out of date with respect to npm
  3. /home/sang/.nvm/versions/node/v4.3.2/bin/nrm -> /home/sang/.nvm/versions/node/v4.3.2/lib/node_modules/nrm/cli.js
  4. nrm@0.3.0 /home/sang/.nvm/versions/node/v4.3.2/lib/node_modules/nrm
  5. ├── ini@1.3.4
  6. ├── only@0.0.2
  7. ├── extend@1.3.0
  8. ├── async@0.7.0
  9. ├── open@0.0.5
  10. ├── commander@2.9.0 (graceful-readlink@1.0.1)
  11. ├── npmconf@0.1.16 (inherits@2.0.1, osenv@0.0.3, ini@1.1.0, semver@2.3.2, mkdirp@0.3.5, once@1.3.3, nopt@2.2.1, config-chain@1.1.10)
  12. ├── node-echo@0.0.6 (jistype@0.0.3, mkdirp@0.3.5, coffee-script@1.7.1)
  13. └── request@2.69.0 (aws-sign2@0.6.0, forever-agent@0.6.1, tunnel-agent@0.4.2, oauth-sign@0.8.1, is-typedarray@1.0.0, caseless@0.11.0, stringstream@0.0.5, isstream@0.1.2, json-stringify-safe@5.0.1, extend@3.0.0, tough-cookie@2.2.1, node-uuid@1.4.7, qs@6.0.2, combined-stream@1.0.5, form-data@1.0.0-rc3, mime-types@2.1.10, aws4@1.3.2, hawk@3.1.3, bl@1.0.3, http-signature@1.1.1, har-validator@2.0.6)

测速

  1. $ nrm test
  2. * npm ---- 274ms
  3. cnpm --- 6868ms
  4. taobao - 716ms
  5. edunpm - 5598ms
  6. eu ----- Fetch Error
  7. au ----- Fetch Error
  8. sl ----- 1234ms
  9. nj ----- 2228ms
  10. pt ----- Fetch Error

切换源

  1. $ nrm use npm
  2. Registry has been set to: https://registry.npmjs.org/