Requiring and Updating Packages
Add packages with composer require and update with composer update.
Requiring and Updating Packages is a free PHP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PHP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
composer require
composer require vendor/package adds the package to composer.json, downloads it, and updates composer.lock in one command.
$ composer require monolog/monologSpecifying a Version
Pin a version constraint when you need a specific range.
$ composer require monolog/monolog "^3.0"Installing Dev Dependencies
Use the --dev flag to add a package under require-dev.
$ composer require --dev phpunit/phpunit "^11.0"What Happens Internally
Composer resolves compatible versions, downloads them to vendor/, updates composer.lock, and regenerates the autoloader.
composer update
composer update recalculates all dependency versions and updates composer.lock.
$ composer update
# Update a single package:
$ composer update monolog/monologinstall vs update
composer install uses the existing lock file (reproducible). composer update recalculates versions. Use install in CI/production.
composer remove
Remove a package and clean up composer.json and composer.lock.
$ composer remove monolog/monologcomposer show
List installed packages and their versions.
$ composer show
$ composer show monolog/monolog # detailed infocomposer outdated
See which installed packages have newer versions available.
$ composer outdatedcomposer why
Find out which packages depend on a given package.
$ composer why monolog/monolog
# laravel/framework requires monolog/monolog ^3.0Semantic Versioning
Most packages follow SemVer: MAJOR.MINOR.PATCH. The ^ constraint allows MINOR and PATCH updates but not MAJOR (breaking) changes.
Summary
Use composer require to add packages and composer update to pull new versions. Lock the file for reproducible builds; run install in production.
Quick Check
Which flag adds a package as a dev-only dependency?
Frequently asked questions
Is the “Requiring and Updating Packages” lesson free?
Yes — the full text of “Requiring and Updating Packages” is free to read here on the web, and the PHP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PHP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Requiring and Updating Packages”?
Add packages with composer require and update with composer update. You practise PHP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start PHP Academy?
No prior experience is required. PHP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Requiring and Updating Packages” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this PHP Academy lesson?
Yes. Every PHP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Installing and Initializing Composer
- Requiring and Updating Packages
- Understanding composer.lock
- Composer Scripts and Autoloading