如何更新Node.js?

本文翻译自:How do I update Node.js?

This post is a Community Wiki . 这篇文章是社区维基 Edit existing answers to improve this post. 编辑现有答案以改善此职位。 It is not currently accepting new answers. 它当前不接受新的答案。

I did the following to update my npm: 我做了以下更新我的npm:

npm update npm -g

But I have no idea how to update Node.js. 但是我不知道如何更新Node.js。 Any suggestions? 有什么建议么? (I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.) (我正在使用Node.js 0.4.1,并想更新到Node.js 0.6.1。)


#1楼

参考:https://stackoom.com/question/YMyJ/如何更新Node-js


#2楼

To control your version of Node.js, you can try n . 要控制您的Node.js版本,可以尝试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. n是Node.js二进制管理,无子shell,无配置文件设置,无复杂的API,非常简单。

npm install -g n

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


#3楼

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

$ brew upgrade node

#4楼

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) 对于最新的LTS版本(在Mac上测试)

sudo n lts

#5楼

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: 清除NPM的缓存:

     sudo npm cache clean -f 
  2. Install a little helper called 'n' 安装一个名为“ n”的小助手

     sudo npm install -gn 
  3. Install latest stable Node.js version 安装最新的稳定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 numbering and 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. 这个已有4年历史的帖子仍然获得投票支持,所以我猜它仍然对很多人有用。 However, Mr. Walsh himself recommended to update Node.js just using nvm instead. 但是,沃尔什先生本人建议仅使用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 Windows the 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. 然后,您可以自由选择安装的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: 因此,如果您需要使用v4.2.0之类的旧版本,则可以将其设置为活动版本,如下所示:

nvm use 4.2

#6楼

On Windows you can use Chocolatey to 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 cinst and cup . 注意:您需要先安装Chocolatey,然后才能使用cinstcup

发布了0 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/p15097962069/article/details/105448439