node.js 如何安装以前确切版本的 NPM 包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15890958/
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
How to install a previous exact version of a NPM package?
提问by stewart99
I used nvm to download node v0.4.10 and installed npm to work with that version of node.
我使用 nvm 下载 node v0.4.10 并安装了 npm 以使用该版本的 node。
I am trying to install express using
我正在尝试使用安装 express
npm install express -g
and I get an error that express requires node version >= 0.5.0.
我收到一个错误,表示 express 需要节点版本 >= 0.5.0。
Well, this is odd, since I am following the directions for a node+express+mongodb tutorial herethat used node v0.4.10, so I am assuming express is/was available to node v0.4.10. If my assumption is correct, how do I tell npm to fetch a version that would work with my setup?
那么,这是奇怪的,因为我下面的指示为节点+快递+ MongoDB的教程这里是使用的节点v0.4.10,所以我假设快递是/是提供给节点v0.4.10。如果我的假设是正确的,我如何告诉 npm 获取适用于我的设置的版本?
回答by Bret Copeland
If you have to install an older version of a package, just specify it
如果您必须安装旧版本的软件包,只需指定它
npm install <package>@<version>
For example: npm install [email protected]
例如: npm install [email protected]
You can also add the --saveflag to that command to add it to your package.json dependencies, or --save --save-exactflags if you want that exact version specified in your package.json dependencies.
您还可以将--save标志添加到该命令以将其添加到您的 package.json 依赖项中,或者--save --save-exact如果您想要在您的 package.json 依赖项中指定的确切版本,则添加标志。
The installcommand is documented here: https://docs.npmjs.com/cli/install
该install命令记录在此处:https: //docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
如果您不确定可用的软件包版本,您可以使用:
npm view <package> versions
And npm viewcan be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
并且npm view可用于查看其他东西约一个包了。https://docs.npmjs.com/cli/view
回答by inaps
It's quite easy. Just write this, for example:
这很容易。就这样写,例如:
npm install -g [email protected]
Or:
或者:
npm install -g npm@latest // For the last stable version
npm install -g npm@next // For the most recent release
回答by Saurabh Chandra Patel
First remove old version, then run literallythe following:
首先删除旧版本,然后从字面上运行以下内容:
npm install [email protected]
and for stable or recent
对于稳定的或最近的
npm install -g npm@latest // For the last stable version
npm install -g npm@next // For the most recent release
回答by Oleg Bezkorovaynyi
In my opinion that is easiest and fastest way:
在我看来,这是最简单和最快的方法:
$ npm -v
$ npm -v
4.2.0
4.2.0
$ npm install -g npm@latest-3
$ npm install -g npm@latest-3
...
...
$ npm -v
$ npm -v
3.10.10
3.10.10
回答by Mehedi Abdullah
you can update your npm package by using this command:
您可以使用以下命令更新您的 npm 包:
npm install <package_name>@<version_number>
npm install <package_name>@<version_number>
example:
npm install [email protected]
例子:
npm install [email protected]
回答by Lakshay Sharma
npm install?-g npm@version
npm install?-g npm@version
in which you want to downgrade
你想降级的地方
npm install?-g [email protected]
npm install?-g [email protected]
回答by Alejandro Araujo
I have a general way to solve this type of problems, which could be helpful too, especially when cloning repositories to run them locally, but requires a little more analysis of the versions.
我有一种解决此类问题的通用方法,这也可能会有所帮助,尤其是在克隆存储库以在本地运行它们时,但需要对版本进行更多分析。
With the package npm-check-updatesI verify the versions of the packages (according to the package.json file) that are not declared in their latest available versions, as shown in the figure (https://www.npmjs.com/package/npm-check-updates):
使用该包,npm-check-updates我验证了未在其最新可用版本中声明的包的版本(根据 package.json 文件),如图(https://www.npmjs.com/package/npm-check -更新):
With this information we can verify the update status of the different packages and make decisions as to which packages to upgrade / degrade and which ones do not.
有了这些信息,我们可以验证不同包的更新状态,并决定哪些包要升级/降级,哪些不升级。
Assuming that we decided to update all the packages as they are listed, we can use the ncu -ucommand which only modifies your package.json file. Run npm installto update your installed packages and package-lock.json.
假设我们决定更新所有列出的包,我们可以使用ncu -u只修改 package.json 文件的命令。运行npm install以更新已安装的软件包和 package-lock.json。
Then, depending on the requirements of the repository, we can refine what is needed, installing the specific versions with
npm view <package> versionsand npm install <package>@<version>
然后,根据存储库的要求,我们可以细化所需的内容,使用npm view <package> versions和 安装特定版本
npm install <package>@<version>
回答by Peter Moses
For yarn users:
对于纱线用户:
yarn add package_name@version_number
回答by Pinky
You can use the following command to install a previous version of an npm package:
您可以使用以下命令安装以前版本的 npm 包:
npm install packagename@version
回答by Deepti Gehlot
On Ubuntu you can try this command.
在 Ubuntu 上你可以试试这个命令。
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Specific version : sudo n 8.11.3 instead of sudo n stable
具体版本:sudo n 8.11.3 而不是 sudo n stable


