SemVer Cheatsheet - Semantic Versioning Reference

A careless constraint like ^ or ~ silently decides whether your deploy upgrades dependencies or breaks the build. This reference covers MAJOR.MINOR.PATCH structure, prerelease tags, comparison operators, and the npm ranges you actually write (^ ~ >= < * and advanced combos). Use it to write a package.json that upgrades exactly what you want, and to tell why npm picked version X. After reading you read and write version ranges with intent.

Reference·33 commands·Last updated 2026-07-21
semverVersioningnpmConventions

Version Number Structure 5

MAJOR.MINOR.PATCH
主版本.次版本.修订号
1.2.3
example:主版本 1,次版本 2,修订号 3
MAJOR:不兼容的 API 变更
破坏性Update时递增
MINOR:向下兼容的功能新增
新增功能时递增
PATCH:向下兼容的问题修复
修复 bug 时递增

Pre-release & Build Metadata 6

1.0.0-alpha.1
内部Test版(alpha)
1.0.0-beta.2
公开Test版(beta)
1.0.0-rc.1
候选release版(release candidate)
alpha < beta < rc < 正式版
先行版本号优先级order
1.0.0-alpha < 1.0.0-alpha.1
同标识按数字递增compare
1.0.0+20260721
Build元数据(+ 号,不影响优先级)

Version Comparison Operators 5

=1.2.3
精确Match指定版本
>1.2.3
大于指定版本(不含)
>=1.2.3
大于于指定版本
<2.0.0
小于指定版本(不含)
<=1.9.9
小于于指定版本

npm Version Range Symbols 7

^1.2.3
允许 1.x.x,不允许 2.0.0(兼容版本)
~1.2.3
允许 1.2.x,不允许 1.3.0(接近版本)
1.2.3 - 2.3.4
区间范围(>=1.2.3 且 <=2.3.4)
1.x
通配符,equivalent to >=1.0.0 <2.0.0
1.2.x
通配符,equivalent to >=1.2.0 <1.3.0
*
任意版本(不recommended,易引入破坏性Upgrade)
latest
最新稳定版(dist-tag)

npm Advanced Range Syntax 5

1.2.3 || >=2.0.0
or运算,Match任一范围
>=1.2.3 <2.0.0
空格表示 AND,需同时满足
~1.2 || ^2.0.0
复合范围组合使用
github:owner/repo
从 Git 仓库Install
file:./local-pkg
从本地路径Install

Version Changes & Release Rules 5

feat: 新功能
对应 MINOR 递增
fix: 修复 bug
对应 PATCH 递增
BREAKING CHANGE: 破坏性变更
对应 MAJOR 递增
0.x.x
主版本号为 0 表示初始开发,API 不稳定
1.0.0
首个正式版,标志着公共 API 稳定

Tips

  • ^1.2.3 equals >=1.2.3 <2.0.0 — npm install default behavior.
  • ~1.2.3 equals >=1.2.3 <1.3.0 — only patch updates allowed.
  • package-lock.json locks exact versions, avoiding uncertainty from ^ and ~.
  • Breaking changes must bump the major version, even for tiny changes.
  • At major version 0 (0.x.x), any breaking change should bump the minor version.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us