Course contentsShow
← Software Engineering
Lesson 670 of 1,93321. Build Automation and Dependency ManagementFree lesson

Version Specifiers and Ranges

Using exact versions, ranges, carets, tildes, and wildcards to control which dependency versions are acceptable.

Version Specifiers and Ranges

You'll learn how to control which dependency versions your project accepts using exact versions, ranges, and special operators.

Now that you understand Semantic Versioning (major.minor.patch), you need to know how to specify which versions of a dependency your project will accept. Your build tool uses these specifiers to decide what to download.

Exact Versions

The simplest approach: 1.2.3 means "only version 1.2.3." This is precise but inflexible—you won't get bug fixes automatically.

Ranges

You can specify acceptable bounds:

  • >=1.2.3 means version 1.2.3 or higher
  • >=1.2.0 <2.0.0 means any 1.x version starting from 1.2.0

Caret (^)

The caret operator ^1.2.3 means "compatible with 1.2.3"—it allows minor and patch updates but not major changes. It translates to >=1.2.3 <2.0.0. Think of it as "get updates, but don't break compatibility."

Tilde (~)

The tilde operator ~1.2.3 is more conservative—it allows only patch updates. It means >=1.2.3 <1.3.0. Use this when you want bug fixes but are cautious about new features.

Wildcards

Some tools let you use * or x:

  • 1.2.* or 1.2.x means any patch version of 1.2
  • 1.* means any minor/patch of version 1

Choosing Wisely

Exact versions give control but require manual updates. Carets provide flexibility for receiving non-breaking changes. Tildes are safer but might miss new features. Your choice depends on your project's stability needs and update strategy.

Key Takeaway: Version specifiers like exact versions (1.2.3), carets (^1.2.3), tildes (~1.2.3), and ranges let you balance between getting dependency updates automatically and maintaining control over breaking changes.