Can someone explain to me the difference between NPM
, Bower
and Composer
.
They are all package managers - correct?
But when should each one be used?
Also, each one appears to have a json file that accompanies it, does this store all the packages you require so they can be installed by cmd line? Why do you need this file?
npm
is nodejs package manager. It therefore targets nodejs environments, which usually means server-side nodejs projects or command-line projects (bower itself is a npm package). If you are going to do anything with nodejs, then you are going to use npm.
bower
is a package manager that aims at (front-end) web projects. You need npm and nodejs to install bower and to execute it, though bower packages are not meant specifically for nodejs, but rather for the "browser" environment.
composer
is a dependency manager that targets php projects. If you are doing something with symfony (or plain old php), this is likely the way to go
Summing it up:
- doing node? you do npm
- doing php? try composer
- front-end javascript? try bower
And yes, the "json" files describe basic package information and dependencies. And yes, they are needed.
Now, what about the READMEs? :-)
- https://github.com/bower/bower
- https://www.npmjs.org/doc/cli/npm.html
- https://getcomposer.org/doc/00-intro.md
[update, four years later]
bower
is deprecated, and should not be used anymore for new projects. To a large extent, it has been subsumed into node dependency management (from their website: "While Bower is maintained, we recommend using Yarn and Webpack or Parcel for front-end projects").
yarn
came out of the wood as a better npm
(fixing several of npm
flaws), and this is really what you should use now, as it is the new de-facto standard if you are doing front-end or node development. It does consume the same package.json
as npm, and is almost entirely compatible with it.
- I wouldn't use
composer
at this point (because I wouldn't use php
), although it seems to still be alive and popular
NPM – Package manager for nodejs. It's the world's largest software registry. Open-source developers from every continent use npm to share and borrow packages. Packages are structured to enable you to keep track of dependencies and versions.
Bower – Package manager for front-end web projects. Bower can manage components that contain HTML, CSS, JavaScript, fonts or even image files. Bower doesn’t concatenate or minify code or do anything else - it just installs the right versions of the packages you need and their dependencies. It is also an npm package. So it can be installed via npm.
npm install bower
Composer – Composer is a tool for dependency management in PHP. It is not a package manager in the same sense as Yum or Apt are. It deals with packages or libraries, but it manages them on a per-project basis, installing them in a directory inside your project. By default it does not install anything globally. Thus, it is a dependency manager.
A Tale of Two Package Managers: Composer and NPM
Difference between Bower and NPM
Here is an app that will help to differentiate these package managers. It demonstrates how an application can leverage several package managers at the same time.