1. update
 sudo apt-get  update    
  1. install nodejs
sudo apt-get  install  nodejs

using node -v to check whether install successfully or not.

  1. install npm
sudo apt-get  install  npm

using npm -v to check.

if you not excute 1. command, you will get this error when you install npm. (just run apt-get update to solve it. )

Do you want to continue? [Y/n] y
Err:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main i386 libssl-dev i386 1.0.2g-1ubuntu4.8
  404  Not Found
Err:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main i386 libssl-doc all 1.0.2g-1ubuntu4.8
  404  Not Found
Unable to correct missing packages.
E: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/pool/main/o/openssl/libssl-dev_1.0.2g-1ubuntu4.8_i386.deb  404  Not Found

E: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/pool/main/o/openssl/libssl-doc_1.0.2g-1ubuntu4.8_all.deb  404  Not Found

E: Aborting install.


yum -y install nodejs npm --enablerepo=epel

Sometimes, you may find npm slow, try cnpm:

npm install -g cnpm --registry=https://registry.npm.taobao.org

文章来源于互联网,如有雷同请联系站长删除:Ubuntu/Centos 安装nodejs和npm