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

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

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

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

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

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


当前回答

警告:如果您需要从旧版本(在我的例子中是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

其他回答

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

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

处理节点版本的最佳方法是使用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和npm的最流行和最简单的方法。

 1)Update via library n 

 2)Update via nvm

打开你的终端我正在使用Ubuntu(Linux)

1) 您可以将n安装为任何节点模块(全局)

npm install -g n

OR

如果需要,也可以从源代码安装

cd /tmp
git clone --depth=1 https://github.com/tj/n
cd n
sudo make install

安装后,点击以下命令安装最新版本的节点

n latest 

now check node -v (you see the latest version is installed)

它将安装节点的最新稳定版本。

n stable

或者您可以通过对n添加版本号来安装任何版本,如

n 0.10.33          # Install and use v0.10.33

您可以在以下链接中查看有关n的更多信息,请单击此处

2) 现在是使用NVM的第二种方法安装

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

安装后,点击以下命令安装最新版本的节点

nvm install node 

可以使用ls remote列出可用版本:

nvm ls-remote

如果要安装特定版本

nvm install 6.14.4 

安装后使用任何版本

nvm use node

将npm更新为最新版本

nvm install-latest-npm

希望它会有所帮助!

如果您想了解更多信息,请使用nvm

非挥发性物质Nvm窗口

对于windows,请按照以下步骤进行安装

对于nodejs,应该卸载它并从nodejs.org下载您喜欢的版本对于npm,运行命令中的以下行:

npm i npm