0% found this document useful (0 votes)
8 views

Composer Cheatsheet

The document provides a cheatsheet of common Composer commands for installing, updating, adding, removing, and verifying packages. It lists the command, a brief description, and notes which commands update the composer.json, composer.lock, or both files. Key commands include "composer install" to install dependencies, "composer update" to update existing packages, and "composer require" to add new packages.

Uploaded by

Giova Rossi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Composer Cheatsheet

The document provides a cheatsheet of common Composer commands for installing, updating, adding, removing, and verifying packages. It lists the command, a brief description, and notes which commands update the composer.json, composer.lock, or both files. Key commands include "composer install" to install dependencies, "composer update" to update existing packages, and "composer require" to add new packages.

Uploaded by

Giova Rossi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

composer cheatsheet

All composer commands, depending on your install, may need to use php
composer.phar in the install folder for composer, instead of global/plain composer.

Installing dependencies

Command Description
composer Downloads and installs all the libraries and dependencies outlined in the
install composer.lock file. If the file does not exist it will look for composer.json
and do the same, creating a composer.lock file.

composer Simulates the install without installing anything


install -
-dry-run

This command doesn’t change any file. If composer.lock is not present, it will create it.

composer.lock should always be committed to the repository. It has all the information
needed to bring the local dependencies to the last committed state. If that file is modified
on the repository, you will need to run composer install again after fetching the
changes to update your local dependencies to those on that file.

Updating packages

Command Description

composer update Updates all packages

composer update --with- Updates all packages and its dependencies


dependencies

composer update Updates a certain package from vendor


vendor/package

composer update vendor/* Updates all packages from vendor

composer update --lock Updates composer.lock hash without updating


any packages

This command changes only the composer.lock file.

Updating autoloader

1/3
Command Description

composer dumpautoload -o Generates optimized autoload files

Adding packages

Command Description

composer require Adds package from vendor to composer.json’s require


vendor/package section and installs it

composer require Adds package from vendor to composer.json’s


vendor/package --dev require-dev section and installs it.

This command changes both the composer.json and composer.lock files.

Passing versions

Command Description
composer require vendor/pkg "1.3.2" Installs 1.3.2

composer require vendor/pkg ">=1.3.2" Above or equal 1.3.2

composer require vendor/pkg "<1.3.2" Below 1.3.2

composer require vendor/pkg "1.3.*" Latest of >=1.3.0 <1.4.0

composer require vendor/pkg "~1.3.2" Latest of >=1.3.2 <1.4.0

composer require vendor/pkg "~1.3" Latest of >=1.3.0 <2.0.0

composer require vendor/pkg "^1.3.2" Latest of >=1.3.2 <2.0.0

composer require vendor/pkg "^1.3" Latest of >=1.3.0 <2.0.0

composer require vendor/pkg "^0.3.2" Latest of >=0.3.0 <0.4.0 (for pre-


1.0)

composer require vendor/pkg "dev- From the branch BRANCH_NAME


BRANCH_NAME"

Removing packages

Command Description
composer remove Removes vendor/package from composer.json and
vendor/package uninstalls it

This command changes both the composer.json and composer.lock files.

2/3
Verifying

Command Description
composer outdated -- Show only packages that are outdated directly required by
direct the root package

3/3

You might also like