Quick reference on installing Composer packages from different sources
Andréia Bohner • February 28, 2021
composerA quick reference on how to configure composer.json to install a package from these sources: local directory, GitHub repository, or Packagist.
Install a Local Package
Require a local package on your composer.json by adding on repositories key "type": "path" and providing the directory of your package in url:
"require": {
...
"my/format-converter": "*"
},
"repositories": [
...
{
"type": "path",
"url": "./packages/format-converter"
}
],
Install a Package Directly from GitHub Repository (or other VCS)
"require": {
...
"my/package-name": "dev-main"
},
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/my/package-name"
}
],
Install a Package from Packagist
Packagist is the default Composer package repository.
Install a package from Packagist using composer require <package-name> (it will update composer.json) or by adding it directly in the require key on composer.json and then running composer update <package-name>.
Command Line
$ composer require aws/aws-sdk-php
composer.json
"require": {
...
"aws/aws-sdk-php": "^3.173"
},