我做了以下事情来更新我的npm:

npm update npm -g

但是我不知道如何更新Node.js。有什么建议吗?(我使用Node.js 0.4.1,想更新到Node.js 0.6.1。)


当前回答

任何操作系统(包括Windows, Mac和Linux)

2022年10月更新


只需进入Node.js官方网站(nodejs.org),下载并执行安装程序。

它会处理好所有的事情,只需点击几下“Next”,你就可以在你的机器上运行最新的Node.js版本。自2020年以来,它是更新NodeJS的推荐方式。这是最简单、最不令人沮丧的解决方案。


专业提示

NodeJS installation includes NPM (Node package manager). To check your NPM version use npm version or node --version. If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node. For more details, see the docs for install command. Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date. Operating systems supported by Node.js: Windows, Linux, MacOS, IBM AIX. For Docker users, here's the official Node.js image. For more information on installing Node.js on a variety of less-common operating systems, see this page (there's even Node for Android!). Troubleshooting for Windows: If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command msiexec /package [node msi]


如果我的回答有用,别忘了给它投票 (这里是Anmol Saraf的原始回答,也给它点赞)

其他回答

如果您安装了Homebrew(仅适用于macOS):

$ brew upgrade node

打开CMD并键入

npm i -g npm

任何操作系统(包括Windows, Mac和Linux)

2022年10月更新


只需进入Node.js官方网站(nodejs.org),下载并执行安装程序。

它会处理好所有的事情,只需点击几下“Next”,你就可以在你的机器上运行最新的Node.js版本。自2020年以来,它是更新NodeJS的推荐方式。这是最简单、最不令人沮丧的解决方案。


专业提示

NodeJS installation includes NPM (Node package manager). To check your NPM version use npm version or node --version. If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node. For more details, see the docs for install command. Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date. Operating systems supported by Node.js: Windows, Linux, MacOS, IBM AIX. For Docker users, here's the official Node.js image. For more information on installing Node.js on a variety of less-common operating systems, see this page (there's even Node for Android!). Troubleshooting for Windows: If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command msiexec /package [node msi]


如果我的回答有用,别忘了给它投票 (这里是Anmol Saraf的原始回答,也给它点赞)

使用节点版本管理器(NVM)

它是一个Bash脚本,允许您下载和管理不同版本的node。完整的源代码在这里。

Windows下的nvm有一个单独的项目:github.com/coreybutler/nvm-windows

下面是在windows上对多个版本的节点使用NVM的完整步骤

下载vvm -setup.zip解压并安装。 执行命令NVM列表可用从CMD或git或powershell,这将列出所有可用的节点版本 使用命令NVM安装版本,例如NVM install 12.14.0在机器上安装 最后一次安装使用NVM使用版本使用更新的版本,例如NVM使用12.14.0

在CentOS 7上,您可以执行以下操作:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node
node –v (Should show updated version now)
npm rebuild node-sass (Optional: if you use this)

注意:需要使用符号链接将您的节点二进制文件与最新安装的node .js二进制文件链接起来。