我刚刚安装了Node.js和NPM(节点包管理器)

我安装了NPM以访问其他Node.js模块。

在我安装Node.js和NPM之后,我注意到这两个版本都不可用。

我想知道:如何将Node.js、NPM和我的Node.js模块升级到最新版本?

我需要卸载Node.js和NPM并重新安装最新版本吗?

这是到目前为止我所做尝试的链接。此链接是npm的一部分。


当前回答

你应该看看这个博客使用包管理器安装nodejs

在执行此命令之前。显示运行sudoapt-get-update,确保结果为Readingpackagelists。。。完成,无错误

一步一步(Debian):

sudo apt-get update

安装6_x

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

安装7_x

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

其他回答

如果您使用的是Windows操作系统,请按照说明进行操作

  npm install npm@latest

如果您使用ubuntu,也可以在终端中使用以下命令

  sudo apt-get update
  sudo apt-get upgrade
  sudo npm install npm@latest

首先,检查NPM版本

 npm -v

查看当前NPM版本:

npm view npm version

将npm更新为当前版本:

npm i -g npm

快乐编码,享受生活!此外,如果你有任何困难,请告诉我。

处理节点版本的最佳方法是使用NVM或节点版本管理器安装后,使用以下命令:

nvm list (shows you the list of installed nodejs version)
nvm install nodeversion   (to install the node version, if latest use  @latest) 
nvm use 10.515..   (to use a perticular node version)

安装nodejs版本12.x和最新npm版本的Ubuntu 20最新版本按照以下步骤安装,使用PPA复制整个命令并运行

cd~&&卷曲-sLhttps://deb.nodesource.com/setup_12.x-o&&nodesource_setup.sh&&sudo bash nodesource_seetup.sh&&sudo apt install nodejs&&nodejs-v来源https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04

我知道这个问题是针对Linux机器的,但如果有人在寻找Windows解决方案,只需转到Node.js站点,单击主页上的下载按钮并执行安装程序。

谢天谢地,它处理了一切,只需单击“下一步”按钮,我就可以在我的Windows7机器上运行最新的0.8.15 Node.js版本。

警告:如果您需要从旧版本(在我的例子中是v4.6.0)更新Node,最好从头开始重新安装nodejs(下载链接:https://nodejs.org)否则,npm也会将自己更新到与新Node不兼容的版本(请参阅本讨论)。

这是我在使用npm更新Node(在Windows上)后收到的错误消息

$ npm install -g npm stable
[ . . .]
$ npm 
C:\Users\me\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js:85
      let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supporte
d outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

新安装后,npm再次工作:

$ npm -v
6.5.0
$ node -v
v10.15.0