5.1 Why Package Management is Necessary
Prerequisites: Terminal, Git, and Debugger
Estimated time: 10 minutes
Reading approach: Learn each tool's role before installing dependencies in a real project
You are ready to continue when: you can distinguish between packages, repositories, package managers, manifests, and caches
The development environment already includes a terminal, Git, and a debugger. When a new program needs to parse JSON, first check whether its standard library is sufficient. Add a dependency only when you need more, after checking maintenance and licensing. That library creates new questions: where to download it, which version to choose, what it depends on, and how the team can reproduce the setup.
Five Objects, Each Responsible for One Thing
| Object | Purpose | Example |
|---|---|---|
| Package/Artifact | Reusable code unit that can be published and reused | Python distribution, npm package, JAR |
| Registry/Artifact Repository | Stores packages and metadata | PyPI, npm registry, Maven Central |
| Package Manager/Resolver | Selects and installs dependencies | pip, npm, Maven, Gradle |
| Project Manifest | Declares direct dependencies and project metadata | pyproject.toml, package.json, pom.xml |
| Local Cache | Avoids redundant downloads | pip cache, ~/.npm, ~/.m2/repository |
A cache, a manifest, and a lockfile serve different purposes. Deleting the cache may trigger a new download, but it should not change the project's declarations.
Three Ecosystems' Minimum Entry Points
The following only shows the shape of the commands. Do not execute them in the current repository. The comprehensive experiment at the end of the chapter will create a temporary directory and clearly indicate which steps may require an internet connection.
Python first creates a virtual environment:
python3 -m venv .venv
. .venv/bin/activate
python -m pip --versionNode projects first generate a manifest:
npm init -y
npm install --package-lock-only --ignore-scriptsJava/Maven declares coordinates at pom.xml, then runs the project Wrapper:
./mvnw clean verifyThese tools appear different. Pip primarily installs Python distributions; npm maintains the manifest and lockfile; Maven also executes the compile, test, and package lifecycle. Calling them all "downloaders" would overlook dependency resolution and building.
Questions Before Adding a Dependency
- Are the package names and publishers trustworthy, and is the license suitable for the project?
- Does the maintenance status, supported runtimes, and platforms meet the project's needs?
- What risks do the dependency tree, installation scripts, and artifact sources introduce?
- How does the project lock, upgrade, verify, and remove it?
“Don't reinvent the wheel” is not an absolute rule. A small function might be easier to audit than introducing a large dependency; complex boundaries such as JSON, cryptography, and protocol implementations are not suitable for casual implementation.
Before Continuing
Try to explain the four sentences without looking at the table: A repository stores packages, a manifest describes the project, a cache holds local artifacts, and a resolver constructs a dependency graph from constraints. If you mistakenly consider any two of these as the same thing, it will be easy to fix the wrong part when you encounter an installation failure.