How to update a single library with Composer?

SymfonyComposer Php

Symfony Problem Overview


I need to install only 1 package for my SF2 distribution (DoctrineFixtures).

When I run

php composer.phar update

I get

  - Updating twig/twig (dev-master 39d94fa => v1.13.0)
    The package has modified files:
    M CHANGELOG
    M doc/filters/batch.test
    M doc/filters/index.rst
    M doc/filters/url_encode.rst
    M doc/functions/index.rst
    M doc/tags/index.rst
    M doc/tests/index.rst
    M lib/Twig/Autoloader.php
    M lib/Twig/Compiler.php
    M lib/Twig/CompilerInterface.php
-10 more files modified, choose "v" to view the full list

It appears the last developer edited a lot of files inside vendor.

In order to get around this, I tried

php composer.phar update <package_name>

But that doesn't seem to work. How can I update/install only one library from composer.json?

Symfony Solutions


Solution 1 - Symfony

To install doctrine/doctrine-fixtures-bundle with version 2.1.* and minimum stability @dev use this:

composer require doctrine/doctrine-fixtures-bundle:2.1.*@dev

then to update only this single package:

composer update doctrine/doctrine-fixtures-bundle

Solution 2 - Symfony

If you just want to update a few packages and not all, you can list them as such:

php composer.phar update vendor/package:2.* vendor/package2:dev-master

You can also use wildcards to update a bunch of packages at once:

php composer.phar update vendor/*
  • --prefer-source: Install packages from source when available.
  • --prefer-dist: Install packages from dist when available.
  • --ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.
  • --dry-run: Simulate the command without actually doing anything.
  • --dev: Install packages listed in require-dev (this is the default behavior).
  • --no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
  • --no-autoloader: Skips autoloader generation.
  • --no-scripts: Skips execution of scripts defined in composer.json.
  • --no-plugins: Disables plugins.
  • --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
  • --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
  • --lock: Only updates the lock file hash to suppress warning about the lock file being out of date.
  • --with-dependencies: Add also all dependencies of whitelisted packages to the whitelist.
  • --prefer-stable: Prefer stable versions of dependencies.
  • --prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.

Solution 3 - Symfony

Difference between install, update and require

Assume the following scenario:

composer.json

"parsecsv/php-parsecsv": "0.*"

composer.lock file

  "name": "parsecsv/php-parsecsv",
            "version": "0.1.4",

>Latest release is 1.1.0. The latest 0.* release is 0.3.2

install: composer install parsecsv/php-parsecsv

This will install version 0.1.4 as specified in the lock file

update: composer update parsecsv/php-parsecsv

This will update the package to 0.3.2. The highest version with respect to your composer.json. The entry in composer.lock will be updated.

require: composer require parsecsv/php-parsecsv

This will update or install the newest version 1.1.0. Your composer.lock file and composer.json file will be updated as well.

Solution 4 - Symfony

You can use the following command to update any module with its dependencies

composer update vendor-name/module-name --with-dependencies

Solution 5 - Symfony

You can basically do following one to install new package as well.

php composer.phar require

then terminal will ask you to enter the name of the package for searching.

$ Search for a package []: //Your package name here

Then terminal will ask the version of the package (If you would like to have the latest version just leave it blank)

$ Enter the version constraint to require (or leave blank to use the latest version) []: //your version number here

Then you just press the return key. Terminal will ask for another package, if you dont want to install another one just press the return key and you will be done.

Solution 6 - Symfony

Just use

composer require {package/packagename}

like

composer require phpmailer/phpmailer

if the package is not in the vendor folder.. composer installs it and if the package exists, composer update package to the latest version.

Solution 7 - Symfony

To ensure that composer update one package already installed to the last version within the version constraints you've set in composer.json remove the package from vendor and then execute :

php composer.phar update vendor/package

Solution 8 - Symfony

Because you wanted to install specific package "I need to install only 1 package for my SF2 distribution (DoctrineFixtures)."

php composer.phar require package/package-name:package-version would be enough

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionToolView Question on Stackoverflow
Solution 1 - SymfonyNicolai FröhlichView Answer on Stackoverflow
Solution 2 - SymfonyYosvel Quintero ArguellesView Answer on Stackoverflow
Solution 3 - SymfonyAdamView Answer on Stackoverflow
Solution 4 - SymfonyWolfackView Answer on Stackoverflow
Solution 5 - SymfonyorhankutluView Answer on Stackoverflow
Solution 6 - SymfonyMostafaView Answer on Stackoverflow
Solution 7 - SymfonyTsounabeView Answer on Stackoverflow
Solution 8 - SymfonyThe AnhView Answer on Stackoverflow