107

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?

Tomasz Jakub Rup
  • 9,464
  • 7
  • 44
  • 47
panthro
  • 19,109
  • 50
  • 152
  • 271
  • Also add Yarn (https://yarnpkg.com/), NuGet (https://www.nuget.org/) and Chocolatey (https://chocolatey.org/) in the list, also read: https://en.wikipedia.org/wiki/List_of_software_package_management_systems – mijaved May 20 '21 at 11:23

1 Answers1

199

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? :-)

[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
Mangled Deutz
  • 11,226
  • 6
  • 35
  • 34
  • 7
    What about php+frontent applications? What's the best option? – sompylasar May 25 '14 at 11:30
  • 15
    Depends where you draw the line. Is your MVC in js (and your php is reduced to a WS)? Then likely use bower. Is your MVC in php (say, symfony), and you have a bunch of js hooked into your server side views? Then composer is likely your best pick. – Mangled Deutz May 25 '14 at 16:04
  • @MangledDeutz so can you use composer to manage javascript libraries? – PhoneixS Oct 10 '14 at 08:23
  • 22
    The most annoying and counter productive part is when you are working on libraries where, some only use bower; some only use composer and yet others only use npm. Would be nice to find a single package manager that with a single command handles all these package managers. It should be called Inception. – Angel S. Moreno Oct 25 '14 at 19:39
  • did some googling and found https://github.com/francoispluchino/composer-asset-plugin – Angel S. Moreno Oct 25 '14 at 19:40
  • 30
    I think @AngelS.Moreno is right. There are too many lets make a 4th. :) – Eric Oct 27 '14 at 20:39
  • 1
    @AngelS.Moreno you are right and I would even go further than just stopping at installers and dependency managers. There are too many of everything. Too many JS libraries that do the same, too many PHP Frameworks and so on. If people could just work collaboratively on one thing, it would change life for a lot of us. – JG Estiot May 18 '15 at 07:49
  • @MangledDeutz Composer is not a package manager. It is a dependency manager. This is what I found in the definition. Can you please elaborate in brief about the difference between dependency manager and package manager – Ganesh Babu Nov 12 '15 at 06:18
  • 1
    @GaneshBabu.T.Y : there is no difference IMHO, and Composer is certainly a package manager (the explanation they put forward is quite ridiculous). If you still want to stick with that distinction though, then npm would be both a package and a dependency manager, and bower would be a dependency manager. – Mangled Deutz Dec 01 '15 at 00:42
  • @GaneshBabu Since you depend on a lot of packages for your development, Composer works as a package manager for these dependencies. – anonym Aug 17 '16 at 11:47
  • @AngelS.Moreno https://www.explainxkcd.com/wiki/index.php/1654:_Universal_Install_Script – online Thomas Mar 10 '17 at 13:44
  • 1
    This is out of date now. These days you can use NPM in place of Bower, and lots of people recommend doing just that. NPM is not just limited to nodejs environments. – Chuck Le Butt Apr 13 '17 at 14:05
  • Agreed. I would just use yarn today :) – Mangled Deutz May 26 '17 at 08:33