I am bit confused about commands composer init'
and composer require
If I am correct:
require
init
I have a project and I do NOT want to publish it to https://packagist.org/
I just want to add some libraries to my project.
Do I have to necessarily run composer init
before I run composer require
?
I watched a tutorial, where they use composer init
command before calling composer require
, which confused me, because I though that composer init
was related to publishing a library on packagist.
composer init
just creates an "empty" composer.json
, asking you some questions to fill out boilerplate.
No, it's not a necessary command "to publish a package", just a helper to initialize a project. That project can either be an package or stand-alone project.
require
adds a package to an existing composer.json
, and if the composer.json
file does not exist in that directory it will just creates a blank one for you.
So calling composer init
is certainly not required before running composer require package-name
, but it simply helps you have a more fleshed out composer.json
to start with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With