简体   繁体   English

'npm 是否安装'l<package_name> 安装一个package的最新版本还是安装最新版本的node兼容?</package_name>

[英]Does 'npm instal'l <package_name> install the latest version of a package or the latest compatible with the version of node installed?

Does npm install <package_name> install the latest version of a package or the latest compatible with the version of node installed? npm install <package_name>是否安装最新版本的 package 或与安装的节点版本兼容的最新版本?

What will happen in these 2 cases?这两种情况会发生什么?

Case 1: Node version in the directory is 10.16.0.案例1:目录中的节点版本为10.16.0。 Will 'npm install xyz' install the latest xyz or the latest compatible version with 10.16.0? 'npm install xyz' 会安装最新的 xyz 还是与 10.16.0 兼容的最新版本?

Case 2: Node version in the directory is 10.16.0 Will 'npm install -g xyz' install the latest xyz or the latest compatible with the version of node installed globally OR will it consider 10.16.0?案例2:目录中的节点版本是10.16.0 'npm install -g xyz'会安装最新的xyz还是与全局安装的节点版本兼容的最新版本,还是会考虑10.16.0?

Answer Latest Version HOWEVER回答最新版本但是

If the package is already installed in a project or contained within the package.json file, then the version string Is what NPM will try and use, Which may contain a Caret(^) which tells npm Not to update the Major Version. If the package is already installed in a project or contained within the package.json file, then the version string Is what NPM will try and use, Which may contain a Caret(^) which tells npm Not to update the Major Version.

For more info read below欲了解更多信息,请阅读下文

Npm install will always install the latest Full Release build of the package (Skips -tag.x versions) unless manually specified, which can potentially be incompatible with some versions of node.除非手动指定,否则 Npm 安装将始终安装 package 的最新完整版本版本(跳过-tag.x版本),这可能与某些版本的节点不兼容。 Not all packages specify the engine it is compatible with so sometimes you have to do some digging or trial and error.并非所有软件包都指定了它兼容的引擎,因此有时您必须进行一些挖掘或反复试验。

You can Manually select a version by adding @ to the package.您可以通过在 package 中添加@来手动 select 版本。

For instance, npm install xyz@10.16.0 will install that specific package version.例如, npm install xyz@10.16.0将安装特定的 package 版本。 You can also prefix a version number with a caret (^) to install the latest Minor build, or a tilde (~) to specify the latest patch version.您还可以在版本号前加上插入符号 (^) 以安装最新的 Minor 版本,或使用波浪号 (~) 指定最新的补丁版本。 For example xyz@^1.2.0 could install say 1.8.0, and xyz@~1.2.0 could install 1.2.9, but Never 1.3.0例如 xyz@^1.2.0 可以安装 1.8.0,xyz@~1.2.0 可以安装 1.2.9,但从不安装 1.3.0

For more info on versioning strings read up on Semantic Versioning aka SemVer有关版本控制字符串的更多信息,请阅读 Semantic Versioning aka SemVer

https://github.com/npm/node-semver#versions https://github.com/npm/node-semver#versions

I'm not sure BUT if you already have installed xyz with -g flag it will not install latest version.我不确定但如果您已经使用 -g 标志安装了 xyz,它将不会安装最新版本。

try
npm uninstall -g xyz 
then 
npm install xyz 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM