npm版本过低时的解决办法
npm全名Node Package Manager
1.配置源的三种方法:
1).npmrc文件的作用,就是配置npm源:使用淘宝源的方法就是在文件.npmrc中加入下面的语句vim .npmrc
然后写入下面语句:
registry = https://registry.npm.taobao.org 2)你也可以使用临时淘宝源,而不用配置.npmrc文件:npm --registry https://registry.npm.taobao.org install node-red-contrib-composer@latest 3)全局配置切换到淘宝源: npm config set registry https://registry.npm.taobao.org
2.得到此时的配置源信息:
npm config get registry出现错误:Error: CERT_UNTRUSTED 解决方法:npm config set strict-ssl false然后再运行查看配置源信息命令即可
3.当仅仅只是npm版本过低时: npm i npm -g来下载最新版本 当你发现你的npm和node的版本都太低的时候,你就使用nvm,这样你就可以在电脑中下载多个版本,然后进行切换使用当然,你也可以将之前的node的卸载,但是总是觉得太麻烦了,而且总是有人说卸不干净,所以还不如使用nvm
出处:https://github.com/creationix/nvm
运行命令:wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash[root@280ecf909150 /]# wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash=> Downloading nvm from git to '/root/.nvm'=> Cloning into '/root/.nvm'...remote: Counting objects: 267, done.remote: Compressing objects: 100% (242/242), done.remote: Total 267 (delta 31), reused 86 (delta 15), pack-reused 0Receiving objects: 100% (267/267), 119.47 KiB | 122.00 KiB/s, done.Resolving deltas: 100% (31/31), done.=> Compressing and cleaning up git repository=> Appending nvm source string to /root/.bashrc=> Appending bash_completion source string to /root/.bashrc/usr/lib/node_modules/npm/bin/npm-cli.js:82 let notifier = require('update-notifier')({pkg}) ^^^^^^^^SyntaxError: Unexpected identifier at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:945:3=> Close and reopen your terminal to start using nvm or run the following to use it now: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
你们看到中间有报错,是我之前npm i npm -g留下来的,可能是npm下的版本过高,跟我之前那个node版本不匹配了。先不管它,现在你重新启动终端
然后输入nvm出现 那就代表可以使用了4.然后就可以安装想要安装的node版本,并使用了nvm install v10.5.0结果:Downloading and installing node v10.5.0...Downloading https://nodejs.org/dist/v10.5.0/node-v10.5.0-linux-x64.tar.gz...######################################################################## 100.0%Computing checksum with sha256sumChecksums matched!Now using node v10.5.0 (npm v6.1.0)Creating default alias: default -> v10.5.0然后你就会发现node安装好了,npm也一起安装了新版本[root@280ecf909150 /]# nvm currentv10.5.0[root@280ecf909150 /]# npm -v6.1.0[root@280ecf909150 /]# node -vv10.5.0[root@280ecf909150 /]# nvm ls-remote列出全部可以安装的版本号nvm install 版本号安装指定版本nvm install v7.9.0 nvm use 版本号切换指定版本,切换效果是全局的nvm use v7.8.0nvm current查看当前使用的版本nvm ls查看该系统已经安装的版本,这个命令也能看到当前使用的是哪个版本