Compare Two Semver Versions — Which Is Newer?
Compare two semantic versions to determine which is newer. Learn the comparison algorithm for major, minor, patch, and pre-release components.
Detailed Explanation
Comparing Two Semver Versions
Version comparison answers a simple question: given two versions, which one is newer? The SemVer specification defines a precise algorithm for this.
The Comparison Algorithm
Versions are compared component by component, left to right:
- Compare MAJOR — higher MAJOR wins
- If MAJOR is equal, compare MINOR — higher MINOR wins
- If MINOR is equal, compare PATCH — higher PATCH wins
- If PATCH is equal, compare pre-release identifiers (see below)
- Build metadata is always ignored
Examples
| Version A | Version B | Result | Deciding Factor |
|---|---|---|---|
2.0.0 |
1.9.9 |
A > B | MAJOR: 2 > 1 |
1.3.0 |
1.2.9 |
A > B | MINOR: 3 > 2 |
1.2.4 |
1.2.3 |
A > B | PATCH: 4 > 3 |
1.2.3 |
1.2.3 |
A = B | All equal |
1.2.3 |
1.2.3-alpha |
A > B | Release > pre-release |
1.2.3-beta |
1.2.3-alpha |
A > B | "beta" > "alpha" lexically |
1.2.3+build.1 |
1.2.3+build.2 |
A = B | Build metadata ignored |
Pre-release Comparison
When both versions have pre-release identifiers and the same MAJOR.MINOR.PATCH:
- Split pre-release by dots into tokens
- Compare tokens left to right
- Numeric tokens are compared as integers (
2 < 11) - String tokens are compared lexically (
"alpha" < "beta") - Numeric tokens have lower precedence than string tokens
- Fewer tokens means lower precedence (if prefix matches)
Practical Comparison
1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-rc.1 < 1.0.0
Using the Compare Tab
Enter two versions in the Compare tab to instantly see:
- Which version is newer
- The component-by-component breakdown
- The difference in major, minor, and patch numbers
Sorting Multiple Versions
When you have a list of versions, comparison is applied pairwise to produce a sorted order. The result follows the same rules — major takes priority, then minor, then patch, then pre-release.
Use Case
Determining whether an available update is newer than your currently installed version, building version-aware deployment pipelines, or sorting release lists in changelogs and dashboards.
Try It — Semver Calculator
Related Topics
Sort a List of Versions Using Semver Rules
Version Comparison
Major, Minor, Patch — What Each Number Means
Version Comparison
Comparing Pre-release Versions (alpha, beta, rc)
Version Comparison
Validate a Semver String — Is It Valid Semantic Versioning?
Validation
Semver Version Increment — Calculate the Next Version
Practical Scenarios