如何更新 Node.js?

发布于 2024-12-16 18:30:18 字数 148 浏览 6 评论 0 原文

我执行了以下操作来更新我的 npm:

npm update npm -g

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

I did the following to update my 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.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

晨光如昨 2024-12-23 18:30:19

更新 Node 和 npm 的简单方法:

npm install -g npm@latest

下载最新版本的 Node js 并更新 /install

The easy way to update node and npm :

npm install -g npm@latest

download the latest version of node js and update /install

梦一生花开无言 2024-12-23 18:30:19
$ npm install -g npm stable

帮我更新 npm

$ npm install -g npm stable

worked for me to update npm

陈独秀 2024-12-23 18:30:19

对于 Ubuntu:

sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

来源:https://askubuntu.com /questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

For Ubuntu:

sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

Source: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

隔岸观火 2024-12-23 18:30:19

您可以在 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.

許願樹丅啲祈禱 2024-12-23 18:30:19

根据 Nodejs 官方页面,您可以在Windows 使用 ChocolateyScoop

使用(Chocolatey):

cinst nodejs
# or for full install with npm
cinst nodejs.install

使用(Scoop):

scoop install nodejs

您还可以下载 Windows Installer

According to Nodejs Official Page, you can install&update new node version on windows using Chocolatey or Scoop

Using(Chocolatey):

cinst nodejs
# or for full install with npm
cinst nodejs.install

Using(Scoop):

scoop install nodejs

Also you can download the Windows Installer directly from the nodejs.org web site

魂ガ小子 2024-12-23 18:30:19

正如你们中的一些人已经说过的,最简单的方法是通过 Node.js 包管理器更新 Node.js,npm。如果您是 Linux(在我的情况下基于 Debian 用户)我建议添加这些写入 .bashrc 文件(在主目录中):

function nodejsupdate() {
    ARGC=$#
    version=latest
    if [ $ARGC != 0 ]; then
        version=$1
    fi
    sudo npm cache clean -f
    sudo npm install -g n
    sudo n $version
}

保存后重新启动终端并写入 nodejsupdate 以更新到最新版本的 Node.js 或 nodejsupdate v6 .0.0(对于示例)以更新到特定版本的 Node.js。

奖励:更新 npm(将这些行添加到 .bashrc

function npmupdate() {
    sudo npm i npm -g
}

重新启动终端后,写入 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):

function nodejsupdate() {
    ARGC=$#
    version=latest
    if [ $ARGC != 0 ]; then
        version=$1
    fi
    sudo npm cache clean -f
    sudo npm install -g n
    sudo n $version
}

Restart your terminal after saving and write nodejsupdate to update to the latest version of Node.js or nodejsupdate v6.0.0 (for example) to update to a specific version of Node.js.

BONUS: Update npm (add these lines to .bashrc)

function npmupdate() {
    sudo npm i npm -g
}

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).

朦胧时间 2024-12-23 18:30:19

在 Windows 中,从网站下载节点可执行文件并安装。这对我有用。

In windows download the node executable file from the website and install it. this worked for me.

z祗昰~ 2024-12-23 18:30:19

Node.js 版本更新所需的一切:

$ brew install node

如果您没有 Homebrew;请访问http://brew.sh/

All you need to version update of Node.js:

$ brew install node

If you don't have Homebrew; please go http://brew.sh/.

捶死心动 2024-12-23 18:30:19

只需在当前文件夹上安装新版本即可。我在 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.

是你 2024-12-23 18:30:19
  1. npm clean 缓存 - 你忘记清理你的缓存

  2. npm update -g

    这适用于我的 Windows,我希望它也适用于您:D

  1. npm clean cache - you forget to clean ur cache

  2. npm update -g

    This works on mine Windows, I hope it will also work for you :D

做个少女永远怀春 2024-12-23 18:30:19

如果您想更新 Node.js,只需

npm update

在 Windows cmd 提示符下尝试即可。

否则,如果您想更新任何特定的包,请尝试

npm update <package_name>

示例:

npm update phonegap

If you want to update Node.js, just try

npm update

from your Windows cmd prompt.

Else if you want to update any specific package try

npm update <package_name>

Example:

npm update phonegap
野鹿林 2024-12-23 18:30:19

打开cmd并输入

npm i -g npm

open cmd and type

npm i -g npm
熟人话多 2024-12-23 18:30:18

要升级 Node,您可能首先需要查看当前正在使用的 Node.js 版本:

node --version

找出您可能已安装的 Node.js 版本以及当前正在使用的 Node.js 版本:

nvm ls

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

nvm ls-remote

显然对于 Windows 该命令会更像这样:

nvm ls available

假设你会选择对于 Node.js v8.1.0 安装,您需要键入以下内容来安装该版本:

nvm install 8.1.0

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

nvm use 4.2

就这样了。


2013 年,我使用以下说明在 Mac 上从 Node.js 版本 0.10.6 升级到 0.10.21,有关最新说明,请参阅上文。

2017 年更新:请注意,Walsh 先生本人建议仅使用 nvm 更新 Node.js

  1. 清除 NPM 的缓存:

     sudo npm 缓存清理 -f
    
  2. 安装一个名为 'n' 的小助手

    <前><代码> sudo npm install -gn

  3. 安装最新稳定的 Node.js 版本

     sudo n stable 稳定
    

或者选择一个特定版本并按如下方式安装:

sudo n 0.8.20

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

鸣谢

To upgrade Node you may first want to see which version of Node.js you are currently using:

node --version

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

nvm ls

List all versions of Node.js available for installation:

nvm ls-remote

Apparently for Windows the command would be rather like this:

nvm ls available

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

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:

nvm use 4.2

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.

  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
    

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 numbering and be picky about odd/even numbers.

Credits

儭儭莪哋寶赑 2024-12-23 18:30:18

使用 Node Version Manager (NVM)

它是一个 Bash 脚本,可让您下载和管理不同版本的 Node。完整源代码位于此处

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

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

  1. 下载 nvm-setup.zip 解压并安装它。
  2. 从cmd或gitbash或powershell执行命令nvm list available,这将列出节点在此处输入图像描述
  3. 使用命令 nvm install version 例如 nvm安装 计算机上安装,请使用 nvm use version 使用较新的版本,例如 nvm use 12.14.0
  4. 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

  1. download nvm-setup.zip extract and install it.
  2. execute command nvm list available from cmd or gitbash or powershell, this will list all available version of node enter image description here
  3. use command nvm install version e.g. nvm install 12.14.0 to install on the machine
  4. last once installed use nvm use version to use newer version e.g. nvm use 12.14.0
罪#恶を代价 2024-12-23 18:30:18

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

2024 年 10 月更新


只需访问官方 Node.js 站点 (nodejs.org),下载并执行安装程序。

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

下载 Windows 版 NodeJS,按钮< /a>

下载NodeJS 用于Win/Mac/源代码按钮


专业提示

  • NodeJS 安装包括 NPM(Node 包管理器)。

  • 要检查您的 NPM 版本,请使用 npm versionnode --version

  • 如果您更喜欢 CLI,要更新 NPM,请使用 npm install -g npm,然后使用 npm install -g node

  • 密切关注NodeJS 博客 - 漏洞,这样您就不会错过重要的安全版本。让您的 NodeJS 保持最新。

  • Node.js 支持的操作系统:

    • Windows、Linux、MacOS、IBM AIX。
    • 对于Docker用户,这里是官方Node.js 图像
    • 有关在各种不太常见的操作系统上安装 Node.js 的更多信息,请参阅 此页面(甚至还有适用于 Android 的 Node!)。
  • 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.

Download NodeJS for Windows, buttons

Download NodeJS for Win/Mac/Source Code buttons


Pro tips

  • 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]


If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)

や莫失莫忘 2024-12-23 18:30:18

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

$ brew upgrade node

If you have Homebrew installed (only for macOS):

$ brew upgrade node
许一世地老天荒 2024-12-23 18:30:18

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).

疏忽 2024-12-23 18:30:18

首先更新npm

npm install -g npm stable

然后更新node

npm install -g nodenpm install -g n

版本安装后检查,

node --version< /strong> 或 node -v

First update npm,

npm install -g npm stable

Then update node,

npm install -g node or npm install -g n

check after version installation,

node --version or node -v

硬不硬你别怂 2024-12-23 18:30:18

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

安装节点

cinst nodejs.install

更新节点

cup nodejs.install

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

On Windows you can use Chocolatey to install and update Node.js (and lots of other packages).

Install Node

cinst nodejs.install

Update Node

cup nodejs.install

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

花间憩 2024-12-23 18:30:18

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

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

对于最新稳定版本:

sudo n stable

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

sudo n lts

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 LTS version(Tested on Mac)

sudo n lts
演出会有结束 2024-12-23 18:30:18

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

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

npm install -g 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 is a Node.js binary management, no subshells, no profile setup, no convoluted API, just simple.

npm install -g n

n 0.6.19 will install Node.js v0.6.19.

但可醉心 2024-12-23 18:30:18

简短回答:

转到此页面:下载 | Node.js

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

Short answer:

Go to this page: Download | Node.js

Download the installer for your platform, then install it.

人│生佛魔见 2024-12-23 18:30:18

当我看到我的 Node.js 安装已过时时,我遇到了同样的问题。

这几行代码将处理所有事情(对于 Ubuntu) :

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

此后 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):

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

After this node -v will return you the latest available version.

一曲爱恨情仇 2024-12-23 18:30:18

在 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 二进制文件链接起来。

On CentOS 7 you can do the following:

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)

Note: The symlink is required to link your node binary with the latest Node.js installed binary file.

百善笑为先 2024-12-23 18:30:18

对于 OS X,我有 v5.4.1 并且需要最新版本 6,因此我访问了 Node.js 主页并单击以下链接之一:

Node.js OS X 下载链接

然后我按照安装程序进行操作,然后我神奇地获得了最新版本的 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:

Node.js OS X download links

I then followed the installer and then I magically had the latest version of Node.js and npm.

悲欢浪云 2024-12-23 18:30:18

你可以使用nvm。

  1. http://nodejs.org/ 检查最新版本是什么(例如 v0.10.26)
  2. 运行 nvm安装 v0.10.26

完成。

您可以选择要运行的版本:

nvm ls 列出可用版本并告诉您现在正在使用哪个版本。

nvm use VERSION 将当前节点更改为请求的版本。

nvm alias default VERSION 设置默认版本。下次您获取 nvm.sh 时,这将是加载的版本(请注意,它不会更改当前使用的版本,请运行 nvm use )。

You may use nvm.

  1. Check what is the latest version at http://nodejs.org/ (e.g. v0.10.26)
  2. Run 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, run nvm use for that).

落叶缤纷 2024-12-23 18:30:18

适用于 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.

转角预定愛 2024-12-23 18:30:18

某些 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-releaseyum 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 analogous apt-get or yum 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 and yum install nodejs.

CentOS 6/EPEL6 has 0.10.x which isn't supported upstream since Oct 2016.

梦里人 2024-12-23 18:30:18

今天我在 Windows Git Bash 上运行:

$ npm i node -g

并得到以下输出:

> [email protected] preinstall C:\Users\X\AppData\Roaming\npm\node_modules\node
> node installArchSpecificPackage

+ [email protected]
added 1 package and audited 1 package in 23.368s
found 0 vulnerabilities

C:\Users\X\AppData\Roaming\npm\node -> C:\Users\X\AppData\Roaming\npm\node_modules\node\bin\node
+ [email protected]
added 2 packages from 1 contributor in 26.089s

https://www 上阅读更多相关信息.npmjs.com/package/node

Today I ran on a Windows Git Bash:

$ npm i node -g

and got the following output:

> [email protected] preinstall C:\Users\X\AppData\Roaming\npm\node_modules\node
> node installArchSpecificPackage

+ [email protected]
added 1 package and audited 1 package in 23.368s
found 0 vulnerabilities

C:\Users\X\AppData\Roaming\npm\node -> C:\Users\X\AppData\Roaming\npm\node_modules\node\bin\node
+ [email protected]
added 2 packages from 1 contributor in 26.089s

Read more about it at https://www.npmjs.com/package/node.

寄人书 2024-12-23 18:30:18
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文