如何更新 Node.js?
我执行了以下操作来更新我的 npm:
npm update npm -g
但我不知道如何更新 Node.js。有什么建议吗? (我正在使用 Node.js 0.4.1,并且想要更新到 Node.js 0.6.1。)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我执行了以下操作来更新我的 npm:
npm update npm -g
但我不知道如何更新 Node.js。有什么建议吗? (我正在使用 Node.js 0.4.1,并且想要更新到 Node.js 0.6.1。)
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(30)
更新 Node 和 npm 的简单方法:
下载最新版本的 Node js 并更新 /install
The easy way to update node and npm :
download the latest version of node js and update /install
帮我更新 npm
worked for me to update npm
对于 Ubuntu:
来源:https://askubuntu.com /questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
For Ubuntu:
Source: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
您可以在 Windows 上使用 Chocolatey。它非常易于使用,并且对于让您及时了解其他应用程序也非常有用。
此外,您只需从 https://nodejs.org 下载最新版本并安装即可。
You may use Chocolatey on Windows. It's very easy to use and useful for keeping you updated with other applications too.
Also, you can just simply download the latest version from https://nodejs.org and install it.
根据 Nodejs 官方页面,您可以在Windows 使用 Chocolatey 或 Scoop
使用(Chocolatey):
使用(Scoop):
您还可以下载 Windows Installer
According to Nodejs Official Page, you can install&update new node version on windows using Chocolatey or Scoop
Using(Chocolatey):
Using(Scoop):
Also you can download the Windows Installer directly from the nodejs.org web site
正如你们中的一些人已经说过的,最简单的方法是通过 Node.js 包管理器更新 Node.js,npm。如果您是 Linux(在我的情况下基于 Debian 用户)我建议添加这些写入
.bashrc
文件(在主目录中):保存后重新启动终端并写入
nodejsupdate
以更新到最新版本的 Node.js 或nodejsupdate v6 .0.0
(对于示例)以更新到特定版本的 Node.js。奖励:更新 npm(将这些行添加到
.bashrc
)重新启动终端后,写入
npmupdate
将节点包管理器更新到最新版本。现在您可以通过终端更新 Node.js 和 npm(更简单)。
As some of you already said, the easiest way is to update Node.js through the Node.js package manager, npm. If you are a Linux (Debian-based in my case) user I would suggest to add these lines to your
.bashrc
file (in home directory):Restart your terminal after saving and write
nodejsupdate
to update to the latest version of Node.js ornodejsupdate v6.0.0
(for example) to update to a specific version of Node.js.BONUS: Update npm (add these lines to
.bashrc
)After restarting the terminal write
npmupdate
to update your node package manager to the latest version.Now you can update Node.js and npm through your terminal (easier).
在 Windows 中,从网站下载节点可执行文件并安装。这对我有用。
In windows download the node executable file from the website and install it. this worked for me.
Node.js 版本更新所需的一切:
如果您没有 Homebrew;请访问http://brew.sh/。
All you need to version update of Node.js:
If you don't have Homebrew; please go http://brew.sh/.
只需在当前文件夹上安装新版本即可。我在 Windows 上将我的版本从 v4.x 升级到 v6.10。
Just install the new version over the current folder. I upgraded mine from v4.x to v6.10 on Windows.
npm clean 缓存
- 你忘记清理你的缓存npm update -g
这适用于我的 Windows,我希望它也适用于您:D
npm clean cache
- you forget to clean ur cachenpm update -g
This works on mine Windows, I hope it will also work for you :D
如果您想更新 Node.js,只需
在 Windows cmd 提示符下尝试即可。
否则,如果您想更新任何特定的包,请尝试
示例:
If you want to update Node.js, just try
from your Windows cmd prompt.
Else if you want to update any specific package try
Example:
打开cmd并输入
open cmd and type
要升级 Node,您可能首先需要查看当前正在使用的 Node.js 版本:
找出您可能已安装的 Node.js 版本以及当前正在使用的 Node.js 版本:
列出 Node.js 的所有版本可用于安装:
显然对于 Windows 该命令会更像这样:
假设你会选择对于 Node.js v8.1.0 安装,您需要键入以下内容来安装该版本:
然后,您可以在已安装的 Node.js 版本之间自由选择。因此,如果您需要使用 v4.2.0 等旧版本,您可以将其设置为活动版本,如下所示:
就这样了。
2013 年,我使用以下说明在 Mac 上从 Node.js 版本 0.10.6 升级到 0.10.21,有关最新说明,请参阅上文。
2017 年更新:请注意,Walsh 先生本人建议仅使用 nvm 更新 Node.js。
清除 NPM 的缓存:
安装一个名为 'n' 的小助手
<前><代码> sudo npm install -gn
安装最新稳定的 Node.js 版本
或者选择一个特定版本并按如下方式安装:
对于生产环境,您可能需要注意 版本编号并对奇数/偶数保持挑剔。
鸣谢
To upgrade Node you may first want to see which version of Node.js you are currently using:
Find out which versions of Node.js you may have installed and which one of those you're currently using:
List all versions of Node.js available for installation:
Apparently for Windows the command would be rather like this:
Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:
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:
That should be all.
In 2013 I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac, for more recent instructions see above.
Update from 2017: Please mind, Mr. Walsh himself recommended to update Node.js just using nvm instead.
Clear NPM's cache:
Install a little helper called 'n'
Install latest stable Node.js version
Alternatively pick a specific version and install like this:
For production environments you might want to pay attention to version numbering and be picky about odd/even numbers.
Credits
使用 Node Version Manager (NVM)
它是一个 Bash 脚本,可让您下载和管理不同版本的 Node。完整源代码位于此处。
Windows 版 nvm 有一个单独的项目: github.com/coreybutler/nvm-windows
以下是在 Windows 上将 NVM 用于多个版本的节点的完整步骤
nvm list available
,这将列出节点nvm install version
例如nvm安装 计算机上安装,请使用
nvm use version
使用较新的版本,例如nvm use 12.14.0
Use Node Version Manager (NVM)
It's a Bash script that lets you download and manage different versions of node. Full source code is here.
There is a separate project for nvm for Windows: github.com/coreybutler/nvm-windows
Below are the full steps to use NVM for multiple version of node on windows
nvm list available
from cmd or gitbash or powershell, this will list all available version of nodenvm install version
e.g.nvm install 12.14.0
to install on the machinenvm use version
to use newer version e.g.nvm use 12.14.0
任何操作系统(包括 Windows、Mac 和 Linux)
2024 年 10 月更新
只需访问官方 Node.js 站点 (nodejs.org),下载并执行安装程序。
它将处理所有事情,只需单击几下“下一步”,您就可以在计算机上运行最新的 Node.js 版本。自 2020 年以来,这是更新 NodeJS 的推荐方式。这是最简单、最不令人沮丧的解决方案。
专业提示
NodeJS 安装包括 NPM(Node 包管理器)。
要检查您的 NPM 版本,请使用
npm version
或node --version
。如果您更喜欢 CLI,要更新 NPM,请使用
npm install -g npm
,然后使用npm install -g node
。安装
的文档命令。密切关注NodeJS 博客 - 漏洞,这样您就不会错过重要的安全版本。让您的 NodeJS 保持最新。
Node.js 支持的操作系统:
Windows 疑难解答:
<块引用>
如果有人像我一样在安装过程中遇到文件错误 2502/2503,请运行
通过管理员命令提示符使用命令
msiexec /package [node msi]
获取 .msi
如果我的回答有帮助,请不要忘记投票
(这是Anmol Saraf的原始答案,也给它点赞)
Any OS (including Windows, Mac & Linux)
Updated October 2024
Just go to the official Node.js site (nodejs.org), download and execute the installer program.
It will take care of everything and with a few clicks of 'Next' you'll get the latest Node.js version running on your machine. Since 2020 it's the recommended way to update NodeJS. It's the easiest and least frustrating solution.
Pro tips
NodeJS installation includes NPM (Node package manager).
To check your NPM version use
npm version
ornode --version
.If you prefer CLI, to update NPM use
npm install -g npm
and thennpm install -g node
.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:
Troubleshooting for Windows:
If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)
如果您安装了 Homebrew(仅适用于 macOS):
If you have Homebrew installed (only for macOS):
2024:只需访问 nodejs.org 并使用最新的安装程序。
就是这样,伙计们。它曾经更加复杂,人们使用不同类型的包和策略来管理它。但情况已经变得更好了。
适用于所有平台(Windows、Mac 和 Linux)。
2024: Just go to nodejs.org and use the latest installer.
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.
Works for all platforms (Windows, Mac & Linux).
首先更新
npm
,npm install -g npm stable
然后更新
node
,npm install -g node
或npm install -g n
版本安装后检查,
node --version
< /strong> 或node -v
First update
npm
,npm install -g npm stable
Then update
node
,npm install -g node
ornpm install -g n
check after version installation,
node --version
ornode -v
在 Windows 上,您可以使用 Chocolatey 来安装和更新 Node.js(以及许多其他软件包) )。
安装节点
更新节点
注意:您需要先安装 Chocolatey,然后才能使用
cinst
和cup
。On Windows you can use Chocolatey to install and update Node.js (and lots of other packages).
Install Node
Update Node
Note: You will need to install Chocolatey before you can use
cinst
andcup
.要将节点升级到最新版本或特定版本,您可以执行以下操作:
对于最新稳定版本:
对于最新 LTS 版本(在 Mac 上测试)
To upgrade node to the latest version or to a specific version you can do the following:
For the latest stable version:
For the latest LTS version(Tested on Mac)
要控制您的 Node.js 版本,您可以尝试 n。我发现它非常简单且有用。
n 0.6.19
将安装 Node.js v0.6.19。To control your version of Node.js, you can try n. I found it very straightforward and useful.
n 0.6.19
will install Node.js v0.6.19.简短回答:
转到此页面:下载 | Node.js
下载适合您平台的安装程序,然后安装它。
Short answer:
Go to this page: Download | Node.js
Download the installer for your platform, then install it.
当我看到我的 Node.js 安装已过时时,我遇到了同样的问题。
这几行代码将处理所有事情(对于 Ubuntu) :
此后
node -v
将返回最新的可用版本。I had the same problem, when I saw that my Node.js installation is outdated.
These few lines will handle everything (for Ubuntu):
After this
node -v
will return you the latest available version.在 CentOS 7 上,您可以执行以下操作:
注意:需要符号链接才能将您的节点二进制文件与最新安装的 Node.js 二进制文件链接起来。
On CentOS 7 you can do the following:
Note: The symlink is required to link your node binary with the latest Node.js installed binary file.
对于 OS X,我有 v5.4.1 并且需要最新版本 6,因此我访问了 Node.js 主页并单击以下链接之一:
然后我按照安装程序进行操作,然后我神奇地获得了最新版本的 Node.js 和 npm。
For OS X, I had v5.4.1 and needed the latest version 6 so I went to the Node.js homepage and clicked on one of the links below:
I then followed the installer and then I magically had the latest version of Node.js and npm.
你可以使用nvm。
nvm安装 v0.10.26
完成。
您可以选择要运行的版本:
nvm ls
列出可用版本并告诉您现在正在使用哪个版本。nvm use VERSION
将当前节点更改为请求的版本。nvm alias default VERSION
设置默认版本。下次您获取 nvm.sh 时,这将是加载的版本(请注意,它不会更改当前使用的版本,请运行nvm use
)。You may use nvm.
nvm install v0.10.26
Done.
You can choose which version to run:
nvm ls
list the available versions and tells you which version you are using now.nvm use VERSION
change the current node to the requested version.nvm alias default VERSION
set the default version. The next time you source nvm.sh, this will be the version loaded (note that it doesn't change the version in use right now, runnvm use
for that).适用于 2018 年以上的 macOS
(因为上述所有解决方案对我来说都失败了):
只需访问 官方 Nodejs 网站,下载官方 NodeJS 包并双击安装。这是您能做的最简单、最安全且始终有效的事情。
For macOS in 2018+
(as ALL of the solutions above are failing for me):
Simply go to the official nodejs site, download the official nodejs package and install it by double clicking. It's the most simple, safe and always-working thing you can do.
某些 Linux 发行版(例如 Arch Linux)的软件包存储库中包含 Node.js。在此类系统上,最好使用标准包更新过程,例如 pacman -Suy 或类似的 apt-get 或 yum 命令。
截至目前(2016 年 11 月),EPEL7 提供了 Node.js 的最新版本(6.9.1,这是 Node.js 主页上提供的最新 LTS 版本)。因此,在 CentOS 7 及其衍生版本上,您只需通过
yum install epel-release
和yum install nodejs
添加 EPEL 存储库即可。CentOS 6/EPEL6 有 0.10.x,自 2016 年 10 月起上游不再支持。
Some Linux distributions such as Arch Linux have Node.js in their package repositories. On such systems it is better to use a standard package update procedure, such as
pacman -Suy
or analogousapt-get
oryum
commands.As of now (Nov 2016) EPEL7 offers a pretty recent version of Node.js (6.9.1 which is an up-to-date LTS version offered on the Node.js home page). So on CentOS 7 and derivatives you can just add EPEL repository by
yum install epel-release
andyum install nodejs
.CentOS 6/EPEL6 has 0.10.x which isn't supported upstream since Oct 2016.
今天我在 Windows Git Bash 上运行:
并得到以下输出:
在 https://www 上阅读更多相关信息.npmjs.com/package/node。
Today I ran on a Windows Git Bash:
and got the following output:
Read more about it at https://www.npmjs.com/package/node.
安装nvm(cURL)
$curl -o- https://raw.githubusercontent.com /creationix/nvm/v0.31.1/install.sh | bash
或与 Wget
$ wget -qO- https://raw.githubusercontent.com /creationix/nvm/v0.33.1/install.sh | /creationix/nvm/v0.33.1/install.sh bash
显示已安装版本列表
$ nvm ls
显示可安装版本的列表
$ nvm ls-remote
安装您的首选版本
$ nvm install v7.5.0
将此版本设置为默认版本
$ nvm alias default v7.5.0
Install nvm(cURL)
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
OR with Wget
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
Display list of installed versions
$ nvm ls
Display list of versions that are available to install
$ nvm ls-remote
Install your preferred version
$ nvm install v7.5.0
Set this version as the default
$ nvm alias default v7.5.0