如何更改为旧版本的 Node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7718313/
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:40:38  来源:igfitidea点击:

How to change to an older version of Node.js

node.js

提问by JD Isaacks

I am running Node.js version v0.5.9-preon Ubuntu 10.10.

v0.5.9-pre在 Ubuntu 10.10 上运行 Node.js 版本。

I would like to be using version v0.5.0-pre.

我想使用 version v0.5.0-pre

How do I roll back to the older version of node?

如何回滚到旧版本的节点?

回答by Dennis

*NIX (Linux, OS X, ...)

*NIX (Linux, OS X, ...)

Use n, an extremely simple Node version manager that can be installed via npm.

使用n,一个非常简单的 Node 版本管理器,可以通过 npm 安装。

Say you want Node.js v0.10.x to build Atom.

假设您希望 Node.js v0.10.x 构建Atom

npm install -g n   # Install n globally
n 0.10.33          # Install and use v0.10.33
Usage:
n                            # Output versions installed
n latest                     # Install or activate the latest node release
n stable                     # Install or activate the latest stable node release
n <version>                  # Install node <version>
n use <version> [args ...]   # Execute node <version> with [args ...]
n bin <version>              # Output bin path for <version>
n rm <version ...>           # Remove the given version(s)
n --latest                   # Output the latest node version available
n --stable                   # Output the latest stable node version available
n ls                         # Output the versions of node available

 

 

Windows

视窗

Use nvm-windows, it's like nvmbut for Windows. Download and run the installer, then:

使用nvm-windows,它就像nvm但适用于 Windows。下载并运行安装程序,然后:

nvm install v0.10.33         # Install v0.10.33
nvm use v0.10.33             # Use v0.10.33
Usage:
nvm install [version]        # Download and install [version]
nvm uninstall [version]      # Uninstall [version]
nvm use [version]            # Switch to use [version]
nvm list                     # List installed versions

回答by David EGP

One way is to use NVM, the Node Version Manager.

一种方法是使用 NVM,即节点版本管理器。

Use following command to get nvm

使用以下命令获取 nvm

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

You can find it at https://github.com/creationix/nvm

你可以在https://github.com/creationix/nvm找到它

It allows you to easily install and manage multiple versions of node. Here's a snippet from the help:

它允许您轻松安装和管理节点的多个版本。这是帮助中的一个片段:

Usage:
nvm install <version>       Download and install a <version>
nvm use <version>           Modify PATH to use <version>
nvm ls                      List versions (installed versions are blue)

回答by Abhishek Goel

Why use any extension when you can do this without extension :)

当您可以在没有扩展名的情况下执行此操作时,为什么要使用任何扩展名:)

Install specific version of node

安装特定版本的节点

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

Specific version : sudo n 4.4.4instead of sudo n stable

具体版本:sudo n 4.4.4代替sudo n stable

回答by Mustkeem K

Windows:

视窗:

To downgrade your node.

降级您的节点。

npm install node@<version>
 ex: npm install [email protected]

To downgrade your npm.

降级你的 npm。

npm install -g npm@<version>
 ex: npm install -g [email protected]

Noteclose all your windows where node is running. Browser, editor etc..

注意关闭节点运行的所有窗口。浏览器、编辑器等。

You need to first install node. And if you have installed already you can downgrade the version of node and npm too just run the above commands. If you still did not get luck and did not succeed updating node. Try this. Try installing node globely. ex:

您需要先安装节点。如果你已经安装了,你也可以降级 node 和 npm 的版本,只需运行上面的命令。如果您仍然没有运气并且没有成功更新节点。尝试这个。尝试全局安装节点。前任:

npm install -g [email protected]

Another thing to consider here is to try updating npm if you are looking for the latest version of npm. Run

这里要考虑的另一件事是,如果您正在寻找最新版本的 npm,请尝试更新 npm。跑

npm install npm@latest -g

MAC

苹果电脑

Note: for macthese same commands should work. Hope this resolves.

注意:对于mac,这些相同的命令应该可以工作。希望这能解决。

回答by russiansummer

the easiest way i have found is to just use the nodejs.orgsite:

我发现的最简单的方法是使用 nodejs.org站点:

  1. go to https://nodejs.org/en/download/releases/
  2. find version you want and click download
  3. on mac click the .pkgexecutable and follow the installation instructions (not sure what the correct executable is for windows)
  4. be happy now that you are on the version of node you wanted
  1. https://nodejs.org/en/download/releases/
  2. 找到你想要的版本并点击下载
  3. 在 mac 上单击.pkg可执行文件并按照安装说明进行操作(不确定 Windows 的正确可执行文件是什么)
  4. 现在很高兴你在你想要的节点版本上

回答by Shaun Luttin

Windows

视窗

Downgrade Node with Chocolately

使用 Chocolately 降级节点

Install Chocolatey.Then run:

安装巧克力。然后运行:

choco install nodejs.install -version 6.3.0

Chocolatey has lots of Node versions available.

Chocolatey 有很多可用的 Node 版本

Downgrade NPM

降级 NPM

npm install -g [email protected]

回答by JDBennett

nvmw is no longer maintained, but I found another source that seems to be up to date (as of 1/4/17).

nvmw 不再维护,但我发现了另一个似乎是最新的来源(截至 2017 年 1 月 4 日)。

nvm-windows

nvm-windows

It works. Allowed me to downgrade to 6.3.1

有用。允许我降级到 6.3.1

回答by Cameron Tacklind

The Official Way (Ubuntu)

官方方式(Ubuntu)

If you're on node 12 and want to downgrade to node 10, just remove node and follow the instructions for the desired version:

如果您在节点 12 上并想降级到节点 10,只需删除节点并按照所需版本的说明进行操作:

# Remove the version that is currently installed
sudo apt remove -y nodejs

# Setup sources for the version you want
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

# (Re-)Install Node
sudo apt-get install -y nodejs


Windows

视窗

I found myself wanting to downgrade to LTS on Windows from the bleeding edge. If you're not using a package manager like Chocolatey or a node version manager like nvm or n, just download the .msifor the version you want and install it. You might want to remove the currently installed version via "Add or remove programs" tool in Windows.

我发现自己想从最前沿的位置降级到 Windows 上的 LTS。如果你没有使用像 Chocolatey 这样的包管理器或像 nvm 或 n 这样的节点版本管理器,只需下载.msi你想要的版本并安装它。您可能希望通过 Windows 中的“添加或删除程序”工具删除当前安装的版本。

Chocolatey

巧克力味

I highly recommend chocolatey for keeping installations up to date easily and it is a common way to install Node.js on Windows. I had to remove the bleeding edge version before installing the LTS version:

我强烈推荐 Chocolatey 以轻松保持安装最新,这是在 Windows 上安装 Node.js 的常用方法。在安装 LTS 版本之前,我必须删除最前沿的版本:

choco uninstall nodejs

choco install nodejs-lts


With package.json

package.json

Ensures users of your program use the right version

确保您的程序用户使用正确的版本

You can add nodeas a dependency in package.jsonand control which version is used for a particular project. Upon executing a package.json"script", npm(and yarn) will use that version to run the script instead of the globally installed Node.js.

您可以node作为依赖项添加package.json并控制用于特定项目的版本。执行package.json“脚本”后,npm(和yarn)将使用该版本而不是全局安装的 Node.js 来运行脚本。

The nodepackage accomplishes this by downloading a nodebinary for your local system and puts it into the node_modules/.bindirectory.

node软件包通过node为您的本地系统下载二进制文件并将其放入node_modules/.bin目录中来完成此操作。



Node Version Manager

节点版本管理器

While not very portable, some developers like manually switching which global version of node is active at any given point in time. There are two popular npm packages that provide helpful CLI interfaces for selecting (and automatically installing) whichever version you want for your system: nvmand n. Using either is beyond the scope of this answer.

虽然不是很便携,但一些开发人员喜欢在任何给定的时间点手动切换哪个全局版本的节点处于活动状态。有两个流行的 npm 包提供有用的 CLI 界面,用于选择(并自动安装)您想要的系统版本:nvmn. 使用任何一个都超出了这个答案的范围。

回答by Nathan Bashaw

Another good library for managing multiple versions of Node is N: https://github.com/visionmedia/n

另一个管理多版本 Node 的好库是 N:https: //github.com/visionmedia/n

回答by Gil Shapir

On windows 7 I used the general 'Uninstall Node.js' (just started typing in the search bottom left ,main menu field) followed by clicking the link to the older version which complies with the project, for instance: Windows 64-bit Installer: https://nodejs.org/dist/v4.4.6/node-v4.4.6-x64.msi

在 Windows 7 上,我使用了一般的“卸载 Node.js”(刚开始在搜索左下角的主菜单字段中输入),然后单击指向符合项目的旧版本的链接,例如:Windows 64-bit Installer : https://nodejs.org/dist/v4.4.6/node-v4.4.6-x64.msi