2 Methods to Skip Installing Development Packages in Composer

2 Methods to Skip Installing Development Packages in Composer

Composer separates production packages from development-only packages through the require and require-dev sections in the composer.json file. During deployment or when preparing a production environment, installing only the required runtime packages is often desirable. This tutorial provides 2 methods how to skip installing development packages in Composer.

Example composer.json:

{
    "name": "company/my-project",
    "description": "Project description",
    "type": "project",
    "license": "MIT",
    "require": {
        "symfony/console": "^7.4"
    },
    "require-dev": {
        "phpunit/phpunit": "^13.0"
    }
}

Method 1 - no-dev option

Composer provides the --no-dev option, which skips all packages listed under the require-dev section. The option can be used with the install command as shown below:

composer install --no-dev

Method 2 (Linux) - COMPOSER_NO_DEV before command

Another option is to define the COMPOSER_NO_DEV environment variable for a command execution. When this variable is present, Composer omits development dependencies during installation.

COMPOSER_NO_DEV=1 composer install

Leave a Comment

Cancel reply

Your email address will not be published.