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

Composer Cheat Sheet

This document provides a cheat sheet on using the Composer dependency manager. It outlines commands for installation, configuration, managing dependencies, version constraints, repositories, and other tasks related to using Composer.

Uploaded by

Pas DEN
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)
163 views

Composer Cheat Sheet

This document provides a cheat sheet on using the Composer dependency manager. It outlines commands for installation, configuration, managing dependencies, version constraints, repositories, and other tasks related to using Composer.

Uploaded by

Pas DEN
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/ 2

Composer Cheat Sheet

Installation Configuration
Command Description
Download Composer from https://getcomposer.org/download/ and follow the instructions.
composer config sort-packages true Sort packages in composer.json alphabetically
Enable bash autocompletion:

composer completion bash | sudo tee /etc/bash_completion.d/composer Authentication


Command Description
Installing dependencies composer config --global Authenticate with GitHub using a personal access
Command Description github-oauth.github.com <token> token

composer install Install dependencies from composer.lock composer config --global


Authenticate with Private Packagist using a
http-basic.repo.packagist.com
composer install --no-dev Install without development dependencies username and password
<username> <password>

Managing dependencies Dependency analysis


Command Description Command Description
Add a new dependency to composer.json and composer show List all installed dependencies
composer require <package>
install it
composer show <package> Display detailed information about a package
composer require <package>:<version> Require a specific version of a dependency
composer outdated List dependencies that are outdated
Add a new development dependency to
composer require --dev <package> Check for known security vulnerabilities in
composer.json and install it composer audit
dependencies
Update all dependencies to their latest installable
composer update composer licenses List all licenses of installed dependencies
versions
composer update <package> Update a dependency to its latest installable version
Update all dependencies of a vendor to their latest Creating new Composer projects
composer update <vendor>/*
versions Command Description
Remove a dependency from composer.json and Create a composer.json file in the current
composer remove <package> composer init
uninstall directory
composer create-project <package> Create a new project from a package
Global dependencies
Command Description Other commands
Add a new global dependency to composer.json Command Description
composer global require <package>
and install it
composer --version Show the current Composer version
composer global update Update all global dependencies
composer self-update Update Composer to the latest version

© Nic Wortel, Software Consultant & Trainer - Last updated on August 3, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Version constraints Repositories
Constraint Description Command Description
1.0.2 Exactly version 1.0.2 composer config repositories.foo Add a new repository named foo with the given URL
composer <url> as a Composer repository
>=1.0.2 Version 1.0.2 or higher
composer config repositories.foo vcs Add a new repository named foo with the given URL
>=1.0.2 <1.1.0 Version 1.0.2 or higher but lower than 1.1.0 <url> as a VCS repository
Version 1.0.2 or higher but lower than 1.1.0 or composer config repositories.foo vcs Add a new GitHub repository named foo/bar as a
>=1.0.2 <1.1.0 || >=1.2.0
version 1.2.0 or higher git@github.com:foo/bar.git VCS repository
1.0 - 2.0 Version 1.0 to 2.0 (including 1.0 and 2.0) composer config repositories.foo path Add a new repository named foo with the given
1.0.* Version 1.0 with any patch version <path> path as a path repository

~1.2 Version 1.2 or higher but lower than 2.0


~1.2.3 Version 1.2.3 or higher but lower than 1.3
^1.2 Version 1.2 or higher but lower than 2.0
^1.2.3 Version 1.2.3 or higher but lower than 2.0

© Nic Wortel, Software Consultant & Trainer - Last updated on August 3, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets

You might also like