用nvm安装nodejs

先用git安装NVMgit clone https://github.com/creationix/nvm.git .nvm

cd ~/.nvm and check out the latest version with git checkout v0.33.6

Now add these lines to your ~/.bashrc~/.profile, or ~/.zshrc file to have it automatically sourced upon login: (you may have to add to more than one of the above files)

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

以上出自https://github.com/creationix/nvm/blob/master/README.md#installation

执行nvm list-remote
选择相应的版本

nvm install v8.7.0

最后验证下 node -version
npm -version
原文地址:https://www.cnblogs.com/hyming011/p/7833469.html