npm和node的版本太低时的解决办法

npm版本太低时的解决办法
npm全名Node Package Manager node

 

1.配置源的三种方法:
1).npmrc文件的做用,就是配置npm源:
使用淘宝源的方法就是在文件.npmrc中加入下面的语句linux

vim .npmrcgit

而后写入下面语句:
registry = https://registry.npm.taobao.orggithub


2)你也可使用临时淘宝源,而不用配置.npmrc文件:
npm --registry https://registry.npm.taobao.org install node-red-contrib-composer@latest
   
3)全局配置切换到淘宝源:
 npm config set registry https://registry.npm.taobao.orgnpm

 

2.获得此时的配置源信息:
npm config get registry

出现错误:
Error: CERT_UNTRUSTED
解决方法:
npm config set strict-ssl falsevim

而后再运行查看配置源信息命令便可bash


3.当仅仅只是npm版本太低时:
 npm i npm -g
来下载最新版本composer


当你发现你的npm和node的版本都过低的时候,你就使用nvm,这样你就能够在电脑中下载多个版本,而后进行切换使用ide

固然,你也能够将以前的node的卸载,可是老是以为太麻烦了,并且老是有人说卸不干净,因此还不如使用nvmui

出处: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 0 Receiving 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查看该系统已经安装的版本,这个命令也能看到当前使用的是哪一个版本

相关文章
相关标签/搜索