What Does a Package Manager Do? npm, Composer and pip Explained
A package manager installs, updates and tracks the libraries your project depends on. Learn how npm, Composer and pip work, with simple examples.
In this article
- What Is a Package Manager?
- A Simple Analogy
- Popular Package Managers by Language
- How a Package Manager Works
- Manifest Files and Lock Files
- Dependencies of Dependencies
- Common Commands
- Install vs Update: An Important Difference
- Why Package Managers Matter
- Common Mistakes to Avoid
- Package Manager FAQ
- Key Takeaway
- Mini Cheat Sheet
Almost no modern app is built completely from scratch. Developers reuse thousands of small, ready-made pieces of code written by other people: libraries for dates, payments, image resizing, testing and more.
Keeping track of all those pieces by hand would be a nightmare. That is the job of a package manager.
What Is a Package Manager?
A package manager is a tool that installs, updates, removes and keeps track of the libraries (packages) your project uses.
A package is simply a bundle of reusable code with a name and a version number, like laravel/framework 13.0 or react 19.1.
In simple words: a package manager is an app store for code, plus a shopping list that remembers exactly what you installed.
A Simple Analogy
Imagine you are cooking from a recipe that needs 20 ingredients.
Without a package manager: you walk to 20 different shops, check each label, carry everything home, and hope you bought the right sizes. Next month, your friend wants to cook the same dish and has to repeat the whole trip.
With a package manager: you hand over the recipe's ingredient list, and everything arrives at your door in the exact quantities. Your friend uses the same list and gets the same ingredients.
Popular Package Managers by Language
- npm, Yarn, pnpm for JavaScript and Node.js
- Composer for PHP (used by Laravel and Symfony)
- pip (and newer tools like uv and Poetry) for Python
- Cargo for Rust
- Maven and Gradle for Java
- NuGet for .NET
Operating systems have them too: apt on Ubuntu, Homebrew on macOS and winget on Windows install whole programs instead of code libraries.
How a Package Manager Works
Here is what happens when you install a package:
- You run a command, for example
npm install axios. - The package manager looks up the package in a registry (npmjs.com, Packagist, PyPI).
- It downloads the right version, plus every package that package depends on.
- It saves the files in your project (for example the
node_modulesorvendorfolder). - It records the package and version in your project's manifest file.
Manifest Files and Lock Files
Two files make package managers powerful:
The manifest file
This lists the packages your project needs and which versions are acceptable. Examples are package.json (npm), composer.json (Composer) and requirements.txt or pyproject.toml (Python).
{
"require": {
"php": "^8.3",
"laravel/framework": "^13.0",
"guzzlehttp/guzzle": "^7.8"
}
}
The ^ symbol means "any compatible newer version". So ^7.8 allows 7.9 or 7.10, but not 8.0.
The lock file
This records the exact versions that were actually installed, such as package-lock.json or composer.lock. When a teammate or your server installs packages, the lock file makes sure everyone gets identical versions. This is why "it works on my machine" problems drop dramatically when you commit the lock file.
Dependencies of Dependencies
When you install one package, you often get many more. A single library may depend on five others, which depend on others again. This is called the dependency tree.
The package manager's job is to resolve this tree: find a set of versions that all work together. When two packages need incompatible versions of the same library, you get a dependency conflict, and the package manager will tell you instead of silently breaking your app.
Common Commands
# JavaScript (npm)
npm install # install everything from package.json
npm install dayjs # add a new package
npm update # update within allowed versions
npm uninstall dayjs # remove a package
# PHP (Composer)
composer install
composer require spatie/laravel-sitemap
composer update
# Python (pip)
pip install -r requirements.txt
pip install requests
Install vs Update: An Important Difference
- install uses the lock file and gives you exactly the versions your team already tested. Use it on servers and in CI/CD.
- update looks for newer versions, installs them and rewrites the lock file. Use it deliberately, then test your app.
Running update directly on a production server is a common way to break a working site.
Why Package Managers Matter
- Speed: add a feature in seconds instead of writing it yourself.
- Consistency: every developer and server runs the same versions.
- Security fixes: update one line to pull in a patched version. Tools like
npm auditandcomposer auditwarn you about known vulnerabilities. - Clean repositories: you commit the manifest and lock file, not thousands of library files.
Common Mistakes to Avoid
- Committing the
node_modulesorvendorfolder to Git. Add them to.gitignoreand let the package manager rebuild them. - Not committing the lock file, which leads to different versions on different machines.
- Installing packages you don't need. Every dependency is code you now have to trust and maintain.
- Ignoring security warnings from audit tools.
- Typos in package names. Attackers publish look-alike packages hoping you mistype a popular name.
Package Manager FAQ
Is npm the same as Node.js?
No. Node.js runs JavaScript outside the browser. npm is the package manager that comes bundled with it.
Where are packages downloaded from?
From a public registry such as npmjs.com for JavaScript, Packagist for PHP and PyPI for Python. Companies can also run private registries.
What is the difference between a library and a package?
A library is reusable code. A package is that code bundled with a name, version and metadata so a package manager can install it.
Should I delete the lock file if something breaks?
Usually no. Deleting it forces every package to the newest allowed version, which can introduce more problems. Update the specific package that is causing trouble instead.
Key Takeaway
A package manager downloads the code your project depends on, keeps every version in sync across machines, and makes updates and security fixes a one-line job.
Mini Cheat Sheet
- Package: reusable code with a name and version
- Registry: the online store packages come from
- Manifest: the list of what your project needs
- Lock file: the exact versions that were installed
- Dependency tree: packages that your packages depend on
Related: New to configuration files? Read What Is a .env File? and learn what a framework is.
Join the conversation
What do you think?
Write a comment
No comments yet. Be the first to share a thought.