Comparing Pre-release Versions (alpha, beta, rc)

Compare pre-release versions like 1.0.0-alpha.1, 1.0.0-beta.2, and 1.0.0-rc.1. Understand the ordering rules for numeric and string identifiers.

Version Comparison

Detailed Explanation

Comparing Pre-release Versions

Pre-release versions follow specific ordering rules defined in the SemVer 2.0.0 specification. These rules are critical when you publish alpha, beta, and RC releases.

The Ordering Algorithm

When comparing two pre-release versions with the same major.minor.patch:

  1. Split the pre-release part by dots into identifiers
  2. Compare identifiers left to right
  3. Apply type-specific rules for each pair

Type-Specific Rules

Type A Type B Rule
Number Number Compare as integers (2 < 11)
String String Compare lexically ("alpha" < "beta")
Number String Number is always lower (1 < "alpha")

Complete Ordering Example

1.0.0-0           (numeric: 0)
1.0.0-1           (numeric: 1)
1.0.0-alpha       (string: "alpha")
1.0.0-alpha.0     (string + numeric: "alpha".0)
1.0.0-alpha.1     (string + numeric: "alpha".1)
1.0.0-alpha.beta  (string + string: "alpha"."beta")
1.0.0-beta        (string: "beta")
1.0.0-beta.2      (string + numeric: "beta".2)
1.0.0-beta.11     (string + numeric: "beta".11)
1.0.0-rc.1        (string + numeric: "rc".1)
1.0.0             (release — always highest)

Common Gotchas

Gotcha 1: "11" > "2" but 11 > 2 too (same result, different reasons)

  • If identifiers are numeric strings ("11" and "2"), they are compared as integers
  • So beta.11 > beta.2 — this is correct and intuitive

Gotcha 2: "alpha" > 1

  • String identifiers always have higher precedence than numeric ones
  • So 1.0.0-alpha > 1.0.0-1

Gotcha 3: Longer > Shorter (when prefix is equal)

  • 1.0.0-alpha.1 > 1.0.0-alpha
  • The additional identifier gives it higher precedence

Practical Release Cycle

A typical release cycle might be:

1.0.0-alpha.1 → 1.0.0-alpha.2 → 1.0.0-beta.1 → 1.0.0-rc.1 → 1.0.0

Use Case

Managing a multi-stage release process (alpha, beta, RC) for an npm package or library, ensuring that version ordering reflects the intended progression.

Try It — Semver Calculator

Open full tool