Composer/Laravel: How to add/update a specific package
Asked Answered
V

4

32

How do you add/update a specific package using composer? I'm using the latest Laravel as well not sure if it matters but anything that can help to determine the answer.

I have also tried the following from an old Stackoverflow post I had found, but it didn't work for me. It appended the package to composer.json and then proceeded to update everything anyways. Here is the link: How to update a single library with Composer?

And here is the package I tried to add to my project: https://github.com/barryvdh/laravel-dompdf

Thank you very much for your time and help!

Edit:


Require and update are not working they update everything as well. Is it possible that I'm running the command incorrectly? I'm still green behind the ears when it comes to composer :S

$ composer require barryvdh/laravel-dompdf
lease provide a version constraint for the barryvdh/laravel-dompdf requirement: *
/composer.json has been updated
oading composer repositories with package information
pdating dependencies (including require-dev)
 - Removing orchestra/testbench (v2.1.1)
 - Removing symfony/security (v2.4.3)
 - Removing symfony/translation (v2.4.3)
 - Installing symfony/translation (v2.4.6)
   Loading from cache

 - Removing symfony/http-foundation (v2.4.3)
 - Installing symfony/http-foundation (v2.4.6)
   Loading from cache

 - Removing symfony/event-dispatcher (v2.4.3)
 - Installing symfony/event-dispatcher (v2.5.0)
   Loading from cache

 - Removing symfony/debug (v2.4.3)
 - Installing symfony/debug (v2.4.6)
   Loading from cache

 - Removing symfony/http-kernel (v2.4.3)
 - Installing symfony/http-kernel (v2.4.6)
   Loading from cache

 - Removing symfony/routing (v2.4.3)
 - Installing symfony/routing (v2.4.6)
   Loading from cache

 - Removing symfony/process (v2.4.3)
 - Installing symfony/process (v2.4.6)
   Loading from cache

 - Removing symfony/finder (v2.4.3)
 - Installing symfony/finder (v2.4.6)
   Loading from cache

 - Removing symfony/dom-crawler (v2.4.3)
 - Installing symfony/dom-crawler (v2.4.6)
   Loading from cache

 - Removing symfony/css-selector (v2.4.3)
 - Installing symfony/css-selector (v2.4.6)
   Loading from cache

 - Removing symfony/console (v2.4.3)
 - Installing symfony/console (v2.4.6)
   Loading from cache

 - Removing symfony/browser-kit (v2.4.3)
 - Installing symfony/browser-kit (v2.4.6)
   Loading from cache

 - Removing swiftmailer/swiftmailer (v5.1.0)
 - Installing swiftmailer/swiftmailer (v5.2.0)
   Loading from cache

 - Removing stack/builder (v1.0.1)
 - Installing stack/builder (v1.0.2)
   Loading from cache

  - Removing patchwork/utf8 (v1.1.21)
  - Installing patchwork/utf8 (v1.1.23)
    Loading from cache

  - Removing nesbot/carbon (1.8.0)
  - Installing nesbot/carbon (1.9.0)
    Loading from cache

  - Removing monolog/monolog (1.9.0)
  - Installing monolog/monolog (1.10.0)
    Loading from cache

  - Removing symfony/filesystem (v2.4.3)
  - Installing symfony/filesystem (v2.5.0)
    Loading from cache

  - Installing symfony/security-core (v2.4.6)
    Loading from cache

  - Removing laravel/framework (v4.1.28)
  - Installing laravel/framework (v4.1.30)
    Loading from cache

  - Removing chumper/datatable (2.2.2)
  - Installing chumper/datatable (2.3)
    Loading from cache

  - Removing ivaynberg/select2 (3.4.6)
  - Installing ivaynberg/select2 (3.4.8)
    Loading from cache

  - Installing phenx/php-font-lib (0.2.2)
    Loading from cache

  - Installing dompdf/dompdf (v0.6.1)
    Loading from cache

  - Installing barryvdh/laravel-dompdf (v0.3.1)
    Loading from cache

symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
Generating autoload files
Compiling component files
Generating optimized class loader
Variolous answered 12/6, 2014 at 3:6 Comment(2)
Is there any specific reason as to why you want to update a single package only?Conveyance
Yes, I do not wish to update everything as there may have been changes to any of the various packages that may or may not break the web application so I don't want to take any chances. I might just install composer in a diff directory and add the package I need after which I'll just transfer it over to the vendor in my main application.Variolous
C
37

I tried the following and it seemed to work for me.

You'll have to first add barryvdh/laravel-dompdf to the composer.json file. Then perform the following:

 composer update barryvdh/laravel-dompdf --lock
Conveyance answered 12/6, 2014 at 6:24 Comment(4)
I've tried composer require and I've tried composer update without any luck everytime I run them it updated everything again. I've pasted a screen dump for you to look over and point to what stupid mistake I'm making.Variolous
i've changed the answer with the method that seemed to work for me.Conveyance
I've tried it with --lock at the end as well just now and it still updates everything again. I wonder if it's because the author of the package says to add it to composer as the following "barryvdh/laravel-dompdf": "*" does the composer command have to change if no version number is specified? i.e. composer update "barryvdh/laravel-dompdf":"*" --lock. I'm sorry I'm just unfamiliar with composer so I'm not sure what I have to do exactly please excuse my stupidity. By the way, thank you so much for your help!Variolous
Using Composer in version 1.6.3 this actually did work for me. However, there might be side effects, if the updated package itself has some requirements. New requirements of course will be introduced (updated) by Composer. I'm not sure what happens to existing requirements, those shared with other libraries or the application. Maybe this might result in updates, too. It's not documented AFAIK.Notecase
S
9

here

composer update barryvdh/laravel-dompdf

composer docs

Steatite answered 12/6, 2014 at 4:33 Comment(2)
If you do this, composer update will update everything , and that's what OP's asking, not how to install the libraryScarrow
Thank you 0xshalaby, please see above post and comment as I'm not having much luck with either require or update :(Variolous
P
1

The above solutions did not work for me, however if anyone still faces this problem

composer require <package> --no-update

this works for me when adding a package

Puss answered 9/5, 2021 at 6:44 Comment(0)
R
0

composer update <package> --lock still install all other packages from composer.json.

My workaround is to install the required package on an separate directory and replace the existing folder with this newly installed. I will then change the version in the composer.json to match to the installed version.

Not too sure if I need to change the composer.lock.

Ruelu answered 16/4 at 3:8 Comment(1)
I've removed the question portion of your post, since it doesn't belong in an answer. That part should probably be its own question. You can provide a link to this answer for context. Thanks!Arriaga

© 2022 - 2024 — McMap. All rights reserved.