PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 4, 2022

[FIXED] Do I have to use init before require in composer?

 January 04, 2022     composer-php, php     No comments   

Issue

I am bit confused about commands composer init' and composer require

If I am correct:

  • If I would like to add a library to my project from packagist I need to use require
  • If I would like to publish my library to packagist I need to use 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.


Solution

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.



Answered By - yivi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing