semver
Validate and manipulate semantic version strings
TLDR
Check if a version string respects the semantic versioning format (prints an empty string if it does not match)
Convert a version string to the semantic versioning format
Test if 1.2.3 matches the ^1.0 range (prints an empty string if it does not match)
Test with multiple ranges
Test multiple version strings and return only the ones that match
SYNOPSIS
semver [version | version1 version2 | -i
semver -r
semver --help | --version
PARAMETERS
When called with a single argument, it validates the string and prints the normalized SemVer version if valid. Returns a non-zero exit code if invalid.
Compares two semantic versions. Returns 0 if equal, 1 if version1 > version2, -1 if version1 < version2 (exit code often reflects this comparison).
-i | --increment
Increments the current version by the specified type (e.g., major, minor, patch, premajor, preminor, prepatch, prerelease). Often used with an optional base version.
-r | --range
Checks if the specified version satisfies the given SemVer range (e.g., '^1.0.0', '~1.2.3'). Returns 0 if it satisfies, non-zero otherwise.
--preid
Used with --increment prerelease or similar operations to specify a prerelease identifier (e.g., 'alpha', 'beta', 'rc').
--coerce
Attempts to convert a non-SemVer string into a valid SemVer string if possible (e.g., '1.2' becomes '1.2.0').
--loose
Enables loose parsing, allowing some non-strict SemVer formats (e.g., leading 'v' or extra spaces).
--help
Displays the command's help message and available options.
--version
Prints the version of the semver utility itself.
DESCRIPTION
The semver command-line utility provides tools for working with Semantic Versioning (SemVer) specifications, a widely adopted versioning scheme for software. SemVer defines a MAJOR.MINOR.PATCH format, where increments to each part signify different levels of API compatibility and feature changes.
While not a core Linux utility, semver tools are commonly found in development environments, often as part of language ecosystems (like Node.js or Python) or as standalone utilities. Its primary purpose is to automate and validate version number manipulation, ensuring adherence to the SemVer specification. This includes tasks such as comparing two versions, validating if a string is a valid SemVer, parsing version components, incrementing versions (major, minor, patch, or prerelease), and checking if a version satisfies a given range.
semver is invaluable in continuous integration/continuous deployment (CI/CD) pipelines, release management workflows, and package management systems to maintain consistent and predictable software versioning.
CAVEATS
The semver command is not a standard, pre-installed utility on most Linux distributions. It typically needs to be installed separately, often as part of a development ecosystem (e.g., Node.js's npm package, Python's pip package, or a standalone binary/script).
Due to multiple independent implementations, the exact syntax, available subcommands, and specific options may vary significantly between different semver tools. Users should consult the documentation for the specific semver utility they are using.
THE SEMANTIC VERSIONING SPECIFICATION
The SemVer specification describes version numbers in the format MAJOR.MINOR.PATCH, optionally with pre-release labels (e.g., -alpha.1) and build metadata (e.g., +build123). It strictly dictates how each segment should be incremented:
MAJOR version increments for incompatible API changes.
MINOR version increments for adding backward-compatible functionality.
PATCH version increments for backward-compatible bug fixes.
This consistency helps developers understand the impact of upgrading dependencies and ensures predictable behavior.
HISTORY
The concept of Semantic Versioning (SemVer) itself was formalized by Tom Preston-Werner, co-founder of GitHub, around 2011. Its aim was to provide a simple set of rules and requirements that dictate how version numbers are assigned and incremented, based on the types of changes made (backward-compatible bug fixes, backward-compatible new features, or breaking changes).
As SemVer gained widespread adoption in the software development community, particularly with the rise of package managers like npm and Composer, the need for automated tools to validate, parse, and manipulate these version strings became evident. This led to the creation of various semver command-line utilities and libraries across different programming languages and platforms, each implementing the SemVer specification to aid in consistent release management and dependency resolution.