Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing only single package via Composer without updating other packages

I need to install a single composer package into a project - maatwebsite/excel ~2.1.0. Each time composer updates, it updates all packages in composer.json. How can I avoid updating packages aside from the excel library?

I have tried the following commands but they don't seem to be working:

composer require maatwebsite/excel ~2.1.0
composer require vendor/maatwebsite/excel ~2.1.0
composer update maatwebsite/excel ~2.1.0
composer update vendor/maatwebsite/excel ~2.1.0

I've also tried using the --lock attribute but that's also not working.

Can anybody tell me what I am doing wrong?

like image 738
Laki98 Avatar asked Dec 24 '16 20:12

Laki98


People also ask

How do I update a single package in composer?

if the package is not in the vendor folder.. composer installs it and if the package exists, composer update package to the latest version. Update: require install or update the latest package version. if you want update one package just use update .

Does composer install update packages?

composer update will update our dependencies as they are specified in composer. json . Supposing we have actually installed the 2.0. 1 version of the package, running composer update will cause an upgrade of this package (for example to 2.0.

What is composer lock?

composer. lock records the exact versions that are installed. So that you are in the same versions with your co-workers. composer install. Check for composer.lock file.


2 Answers

To install a composer package with a specific version the docs suggest the use of a colon.

composer require maatwebsite/excel:~2.1.0 --no-update

Also, the composer cli tool composer help require help reads:

Required package name optionally including a version constraint, e.g. foo/bar or foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"

So to use a space separated version number, you needed the quotation marks surrounding the package/version combination. That is:

composer require "maatwebsite/excel ~2.1.0" --no-update

should work for you too.

like image 153
Ross Avatar answered Sep 30 '22 16:09

Ross


To skip updates on any other package, simply add --no-update to your call. This instructs Composer to only require that new package and not update anything else.

The resulting call could then look like the following:

composer require maatwebsite/excel ~2.1.0 --no-update
like image 30
Nico Haase Avatar answered Sep 30 '22 18:09

Nico Haase