Before going to understand the difference between require and require_dev first understand what is require and require_dev.
require: These are must packages for the code to run. It defines the actual dependency as well as package version.
require_dev: It defines the packages necessary for developing the project and not needed in production environment.
Note: The require and require_dev are important parameters available in composer.json.
What is composer?
Composer is dependency/parameter manager in php. It can be used to install keep a track of and update project dependency. Composer also takes care of autoload of dependencies that application relies on letting easily use the dependency inside the project without worrying about including them at the top of any given file. Dependency for project are listed within a “composer.json” file which typically located in the project root. This file holds the information about required version of packages for production and development. This file can be edited manually using any text editor or automatically through the command line via command such as “composer require ” or “composer require_dev .
To start using composer in the project first need to create composer.json file. It can be either created manually or simply run composer init. After run composer init in the terminal it will ask some basic information about the project such as package name, description (it is optional), Author and source other information like minimum stability, license and required package.
The require key in the composer.json specifies composers which packages the project depends on require takes an object that maps package names
In the above example “composer/composer” specifies vendor name and project name separated by slash (‘/’) and “1.2.*” specifies the version name.
To install the dependency need to run the composer install command and then it will find the defined package that method for supplied version constraints and download it into vendor directory. It convention to put third party code into directory named vendor. The installed command also created a composer.lock file.
Difference Between require and require_dev:
- It define actual dependency as well as package version.
- The require lists the package require by this package.
- The package will not be installed unless those requirements can be met.
- It define the packages necessary for developing project.
- The require_dev lists packages required for developing this package, or running tests, etc.
- The dev requirements of the root package are installed by default. Both install or update support the “–no-dev” option that prevents dev dependencies from being installed.
- PHP | (Include and Require)
- Scala | Preconditions(assert, assume, require, ensuring)
- Difference between “!==” and “==!” in PHP
- Difference between JSP and ASP
- Difference between ASP and ASP.NET
- What is the difference between GUI and CUI?
- What is the difference between (NaN != NaN) & (NaN !== NaN)?
- Web 1.0, Web 2.0 and Web 3.0 with their difference
- Difference Between HTML and ASP
- Difference between array() and  in PHP
- What is the difference between Perl and PHP ?
- What is the difference between CSS and SCSS ?
- Difference between Where and Group By
- What is the difference between the | and || or operator in php?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.