Pinning Dependencies
What you'll learn: How locking exact versions of dependencies guarantees identical builds across machines and time.
When you declare a dependency like requests >= 2.0, your package manager can install any version from 2.0 upward—maybe 2.28 today, 2.31 next week. This creates non-determinism: different developers (or CI servers) might get different versions, leading to subtle bugs or build failures.
Pinning solves this by recording exact versions of every dependency—direct and transitive—in a lock file. Think of it like taking a snapshot: you're freezing the entire dependency tree at a specific moment.
How Lock Files Work
When you first resolve dependencies, your build tool generates a lock file (e.g., package-lock.json, Gemfile.lock, poetry.lock, requirements.txt with hashes). This file lists:
- Every package name
- The exact version installed
- Checksums (hashes) to verify integrity
- The full transitive dependency graph
Anyone running the build with this lock file gets identical versions—no surprises.
The Analogy
Imagine a recipe that says "use fresh tomatoes." One chef buys them Monday, another Friday—they taste different. Pinning is like specifying: "Roma tomatoes, harvested June 15, 2024, from Farm X." Everyone gets the same ingredient.
Pinning vs Flexible Versioning
- Flexible ranges (
>=,~,^) allow updates but risk breaking changes sneaking in - Pinned versions guarantee reproducibility but require deliberate updates
Most teams use flexible ranges in their dependency declaration but rely on lock files to pin actual installations.
Key Takeaway:
Lock files pin exact versions of all dependencies, ensuring every build resolves identically—eliminating "works on my machine" surprises caused by version drift.