如何更新 Node.js?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8191459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:47:40  来源:igfitidea点击:

How do I update Node.js?

node.jssoftware-update

提问by alexchenco

I did the following to update my npm:

我做了以下更新我的 npm:

npm update npm -g

But I have no idea how to update Node.js. Any suggestions? (I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.)

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

采纳答案by pradeek

Use Node Version Manager (NVM)

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

It's a Bash script that lets you download and manage different versions of node. Full source code is here.

它是一个 Bash 脚本,可让您下载和管理不同版本的节点。完整的源代码在这里

There is a separate project for nvm for Windows: github.com/coreybutler/nvm-windows

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

Below are the full steps to use NVM for multiple version of node on windows

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

  1. download nvm-setup.zipextract and install it.
  2. execute command nvm list availablefrom cmd or gitbash or powershell, this will list all available version of node enter image description here
  3. use command nvm install versione.g. nvm install 12.14.0to install on the machine
  4. last once installed use nvm use versionto use newer version e.g. nvm use 12.14.0
  1. 下载nvm-setup.zip解压并安装它。
  2. nvm list available从 cmd 或 gitbash 或 powershell执行命令,这将列出节点的所有可用版本在此处输入图片说明
  3. 使用命令nvm install versionegnvm install 12.14.0在机器上安装
  4. 最后一次安装用于nvm use version使用较新的版本,例如nvm use 12.14.0

回答by Oliver Schafeld

I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac.

我使用以下说明在 Mac 上从 Node.js 版本 0.10.6 升级到 0.10.21。

  1. Clear NPM's cache:

    sudo npm cache clean -f
    
  2. Install a little helper called 'n'

    sudo npm install -g n
    
  3. Install latest stable Node.js version

    sudo n stable
    
  1. 清除 NPM 的缓存:

    sudo npm cache clean -f
    
  2. 安装一个名为“n”的小助手

    sudo npm install -g n
    
  3. 安装最新的稳定 Node.js 版本

    sudo n stable
    

Alternatively pick a specific version and install like this:

或者选择一个特定版本并像这样安装:

sudo n 0.8.20

For production environments you might want to pay attention to version numberingand be picky about odd/even numbers.

对于生产环境,您可能需要注意版本编号并对奇数/偶数进行挑剔。

Credits

学分



Update (June 2017):

更新(2017 年 6 月):

This four years old post still receives up-votes so I'm guessing it still works for many people. However, Mr. Walsh himself recommended to update Node.js just using nvminstead.

这篇四年前的帖子仍然收到了赞成票,所以我猜它仍然适用于许多人。不过,沃尔什先生本人建议只使用NVM Node.js的更新替代。

So here's what you might want to do today:

所以这就是你今天可能想做的事情:

Find out which version of Node.js you are using:

找出您正在使用的 Node.js 版本:

node --version

Find out which versions of Node.js you may have installed and which one of those you're currently using:

找出您可能安装了哪些版本的 Node.js 以及您当前使用的是哪个版本:

nvm ls

List all versions of Node.js available for installation:

列出可供安装的所有 Node.js 版本:

nvm ls-remote

Apparently for Windowsthe command would be rather like this:

显然,对于 Windows,命令应该是这样的:

nvm ls available

Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:

假设您选择 Node.js v8.1.0 进行安装,您可以键入以下内容来安装该版本:

nvm install 8.1.0

You are then free to choose between installed versions of Node.js. So if you would need to use an older version like v4.2.0 you would set it as the active version like this:

然后,您可以在已安装的 Node.js 版本之间自由选择。因此,如果您需要使用像 v4.2.0 这样的旧版本,您可以将其设置为活动版本,如下所示:

nvm use 4.2

回答by Will

If you have Homebrewinstalled (only for macOS):

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

$ brew upgrade node

回答by naXa

This is a simple solution that works for all supported operating systems* including Windows:

这是一个简单的解决方案,适用于所有受支持的操作系统*,包括Windows

After a lot of surfing and not finding a straight solution, I just tried going to Node.jssite, clicked the DOWNLOADSbutton on homepage and executed the installer program (MSI).

Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest Node.js version running on my Windows machine.

经过大量冲浪并没有找到直接的解决方案,我只是尝试转到Node.js站点,单击主页上的DOWNLOADS按钮并执行安装程序 (MSI)。

值得庆幸的是,它处理了所有事情,只需点击几下“下一步”按钮,我就可以在我的 Windows 机器上运行最新的 Node.js 版本。

(here is the original answer)

(这是原始答案

Download NodeJS buttons

下载 NodeJS 按钮

For Dockerusers, here's the official Node.js image.

对于Docker用户,这里是官方的Node.js 镜像



PS:To check your Node version use npm versionor node --version.
PPS:Keep an eye on NodeJS blog - Vulnerabilitiesso you don't miss important security releases.

PS:要检查您的 Node 版本,请使用npm versionnode --version.
PPS:密切关注NodeJS 博客 - 漏洞,这样您就不会错过重要的安全版本。

* Operating systems supported by Node.js: Windows, Linux, MacOS, SunOS, IBM AIX

* Node.js 支持的操作系统:WindowsLinuxMacOSSunOSIBM AIX

回答by swelet

All platforms (Windows, Mac & Linux)

所有平台(Windows、Mac 和 Linux)

Updated (Apr 2020)

更新(2020 年 4 月)



Alternative 1: Through installer

备选方案 1:通过安装程序

Just go to nodejs.organd use the latest installer.

只需转到nodejs.org并使用最新的安装程序即可。



Alternative 2 : Through NPM

备选方案 2:通过 NPM

npm install -g npm stable

npm install -g npm stable

npm install -g node

npm install -g node



That's it folks. It used to be more complex and people used different kinds of packages and strategies to manage it. But things have changed for the better.

就是这样的人。它曾经更加复杂,人们使用不同种类的包和策略来管理它。但事情已经变好了。

回答by AndreL

First update npm,

第一次更新npm

npm install -g npm stable

npm install -g npm stable

Then update node,

然后更新node

npm install -g nodeor npm install -g n

npm install -g node或者 npm install -g n

check after version installation,

版本安装后检查,

node --versionor node -v

node --version或者 node -v

回答by rob

On Windowsyou can use Chocolateyto install and update Node.js (and lots of other packages).

Windows 上,您可以使用Chocolatey来安装和更新 Node.js(以及许多其他包)。

Install Node

安装节点

cinst nodejs.install

Update Node

更新节点

cup nodejs.install

Note: You will need to install Chocolatey before you can use cinstand cup.

注意:您需要先安装 Chocolatey,然后才能使用cinstcup

回答by Clément Renaud

To control your version of Node.js, you can try n. I found it very straightforward and useful.

要控制您的 Node.js 版本,您可以尝试n。我发现它非常简单和有用。

n is a Node.js binary management, no subshells, no profile setup, no convoluted API, just simple.

n 是一个 Node.js 二进制管理,没有子 shell,没有配置文件设置,没有复杂的 API,只是简单。

npm install -g n

n 0.6.19will install Node.js v0.6.19.

n 0.6.19将安装 Node.js v0.6.19。

回答by user1429844

To upgrade node to the latest version or to a specific version you can do the following:

要将节点升级到最新版本或特定版本,您可以执行以下操作:

sudo npm install n -g
sudo n 0.10.18   // This will give you the specific version

For the latest stable version:

对于最新的稳定版本:

sudo n stable

For the latest LTSversion(Tested on Mac)

对于最新的LTS版本(在 Mac 上测试)

sudo n lts

回答by haotang

Short & stupid answer:

简短而愚蠢的答案:

Go to this page: Download | Node.js

前往此页面:下载 | 节点.js

Download the installer for your platform, then install it.

下载适用于您平台的安装程序,然后安装它。