I have a project with a few dependencies and I'd like to install another one, but I'd like to keep the others the way they are. So I've edited the composer.json
, but if I run composer install
, I get the following output:
Installing dependencies from lock file Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them. Your requirements could not be resolved to an installable set of packages. Problem 1 - laravel/framework dev-master requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system. - laravel/framework dev-master requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system. - Installation request for laravel/framework dev-master -> satisfiable by laravel/framework dev-master.
First of all, I do have mcrypt installed, so I don't know why it's complaining about that there.
So, how can I install this new dependency?
My composer.json:
{ "require": { "opauth/opauth": "*", "opauth/facebook": "*", "opauth/google": "*", "opauth/twitter": "*", "imagine/Imagine": "dev-develop", "laravel/framework": "4.*", "loic-sharma/profiler": "dev-master" }, "autoload": { "classmap": [ "app/libraries", "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/tests/TestCase.php" ] }, "minimum-stability": "dev" }
To initially install the defined dependencies for your project, you should run the update command. This will make Composer do two things: It resolves all dependencies listed in your composer. json file and writes all of the packages and their exact versions to the composer.
composer update is mostly used in the 'development' phase, to upgrade our project packages. composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.
--no-update: Disables the automatic update of the dependencies (implies --no-install). --no-install: Does not run the install step after updating the composer. lock file. --no-audit: Does not run the audit steps after updating the composer.
To install a new package and only that, you have two options:
Using the require
command, just run:
composer require new/package
Composer will guess the best version constraint to use, install the package, and add it to composer.lock
.
You can also specify an explicit version constraint by running:
composer require new/package ~2.5
–OR–
Using the update
command, add the new package manually to composer.json
, then run:
composer update new/package
If Composer complains, stating "Your requirements could not be resolved to an installable set of packages.", you can resolve this by passing the flag --with-dependencies
. This will whitelist all dependencies of the package you are trying to install/update (but none of your other dependencies).
Regarding the question asker's issues with Laravel and mcrypt: check that it's properly enabled in your CLI php.ini. If php -m
doesn't list mcrypt then it's missing.
Important: Don't forget to specify new/package
when using composer update
! Omitting that argument will cause all dependencies, as well as composer.lock
, to be updated.
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! 😉
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With