Actually, the correct solution is:
composer require vendor/package
Taken from the CLI documentation for Composer:
The
require
command adds new packages to thecomposer.json
file from the current directory.
php composer.phar require
After adding/changing the requirements, the modified requirements will be installed or updated.
If you do not want to choose requirements interactively, you can just pass them to the command.
php composer.phar require vendor/package:2.* vendor/package2:dev-master
While it is true that composer update
installs new packages found in composer.json, it will also update the composer.lock file and any installed packages according to any fuzzy logic (>
or *
chars after the colons) found in composer.json! This can be avoided by using composer update vendor/package
, but I wouldn't recommend making a habit of it, as you're one forgotten argument away from a potentially broken project…
Keep things sane and stick with composer require vendor/package
for adding new dependencies!