当前位置: 首页 > 工具软件 > least.js > 使用案例 >

将Node.js升级到最新版本

子车高超
2023-12-01

本文翻译自:Upgrading Node.js to latest version

So, I have Node.js installed and now when I tried to install Mongoosejs I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed). 所以,我已经安装了Node.js,现在当我尝试安装Mongoosejs时,出现一个错误消息,告诉我我没有所需的Node.js版本(我需要v0.4.11和v0.4.12)。

How can I upgrade to this version? 如何升级到此版本? I suppose I just could install it again with the latest version, but I don't want to do it before I'm sure that my project folders in the folder "node" won't be deleted. 我想我可以再次安装最新版本,但是在确定不会删除“节点”文件夹中的项目文件夹之前,我不想这样做。


#1楼

参考:https://stackoom.com/question/gHDy/将Node-js升级到最新版本


#2楼

Linux/Mac: Linux / Mac:

The module n makes version-management easy: 模块n使版本管理变得容易:

sudo npm install n -g

For the latest stable version: 对于最新的稳定版本:

sudo n stable

For the latest version: 对于最新版本:

sudo n latest

Windows: 视窗:

just reinstall node from the .msi in Windows from the node website . 只需从节点网站上的 Windows中的.msi重新安装节点。


#3楼

2019 Solution Without using sudo ! 2019 解决方案不使用sudo

The current stable "LTS" version of node is 12.13.1 ( 2019-11-26 ) see : nodejs.org for latest . 当前稳定的节点“ LTS”版本为12.13.12019-11-26 ),有关最新信息, 请参见nodejs.org

Step 1 - Get NVM (Node Version Manger) 第1步- 获取NVM (节点版本管理器)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash

If you're curious about the installation command read the source code 如果您对安装命令感到好奇 ,请阅读 源代码
... its been reviewed by several node.js security experts ...它已经由多位 node.js安全专家进行了审查

Step 2 - Install the version of node.js you need 第2步- 安装所需的node.js版本

Once you've got NVM you can install a specific version of Node.js using the nvm command: 获得NVM后 ,可以使用nvm命令安装特定版本的Node.js:

nvm install v12.13.1

Note : you may need to close & re-open your terminal window for nvm command to be available. 注意 :您可能需要关闭并重新打开终端窗口才能使nvm命令可用。

You should expect to see something like this in your terminal: 您应该期望在终端中看到以下内容:

Now using node v12.13.1

Step 3 - Enjoy the rest of your day! 第3步- 享受您余下的一天!

Yes , it's that easy and didn't require sudo ! 是的 ,就是这么简单 ,不需要sudo
Now please Upvote this ( so others can avoid sudo -installing things! ) 现在请对此进行投票这样其他人可以避免sudo -installing !!
and have a lovely day writing node.js code! 愉快地编写node.js代码!

Microsoft Windows User ? Microsoft Windows用户 Use : https://github.com/coreybutler/nvm-windows 使用https : //github.com/coreybutler/nvm-windows

tl;dr tl; dr

Review of the node mailing list indicates that using NVM ( Node Version Manager ) is the preferred way to manage your nodejs versioning/upgrading. 查看节点邮件列表表明,使用NVM节点版本管理器 )是管理Node.js版本/升级的首选方法。 see: github.com/nvm-sh/nvm 参见: github.com/nvm-sh/nvm

NVM is considered " better " than N because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. 因为冗长的命令的意思是容易跟踪你在你的终端/ SSH登录在做什么NVM被认为是“ 更好 N多。 Its also faster , saves kittens by not requiring sudo and is used by the team at NPM the node.js security experts ! 它也更快不需要 sudo 可以节省小猫NPM的团队使用node.js 安全专家


#4楼

via npm: 通过npm:

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

and also you can specify a desired version: 并且您还可以指定所需的版本:

# n 0.8.21

reference 参考


#5楼

my 2c: 我的2c:

I tried both with n and with nvm on Linux Ubuntu 12.04 LTS, in order to update node from v0.8.25 to v0.10.22. 为了将节点从v0.8.25更新到v0.10.22,我在Linux Ubuntu 12.04 LTS上同时尝试了n和nvm。

The first one was successfully completed, but the command 'which node' resulted in the old v0.8.25. 第一个成功完成,但是命令“哪个节点”导致了旧的v0.8.25。
The second one was successfully completed and the same command resulted in v.0.10.22. 第二个已成功完成,并且相同的命令产生了v.0.10.22。


#6楼

Upgrading node.js to the latest version on Windows 在Windows上将node.js升级到最新版本

  1. Install chocolatey if you haven't already: Installing Chocolatey 如果尚未安装Chocolatey,请执行以下操作安装Chocolatey

  2. From the command prompt, type 在命令提示符下,键入

    cup nodejs

(which is equivalent to typing choco upgrade nodejs -- assumes you already have node installed) (这相当于键入choco upgrade nodejs -假设您已经安装了节点)

NOTE: You may need to run cinst nodejs.install for chocolatey to register your existing installation. 注意:您可能需要运行cinst nodejs.install以获得Chocolatey来注册现有安装。 (thanks for the comment, @mikecheel) (感谢您的评论,@ mikecheel)


Installing node.js on Windows 在Windows上安装node.js

If you have never installed node, you can use chocolatey to do that as well. 如果您从未安装过节点,那么也可以使用Chocolatey来完成。 Install chocolatey (see step 1 above). 安装巧克力味(请参阅上面的步骤1)。 Then from a command prompt, type: 然后在命令提示符下键入:

cinst nodejs.install

Chocolatey Gallery Node JS (Install) Chocolatey Gallery Node JS(安装)


Installing a specific version of node on Windows with chocolatey 使用Chocolatey在Windows上安装特定版本的节点

cinst nodejs.install -Version 0.10.26

 类似资料: