If you want to use Composer, it must be installed either on a local development server or your live site. See Section 3.2, “Concept: Additional Tools”.
If you are unable to install the Composer tool on your live server, you can follow the steps in any of the sections below on your local server, and then transfer any updated or added files to your live server. The recommended procedure is to make an archive or zip file of the new and changed directories, transfer the archive to your live server, delete the directories that have changed, and extract the archive. Make sure to check for updates and additions to the following files, in the root of your installation:
- vendor directory
Follow these steps if you have not yet downloaded or installed the core software, and you want to use Composer to download both the core software and its external dependencies:
- At the command line, change to one level above the directory where you want the software to reside.
Enter this command, where mydir is the directory you want to create:
composer create-project drupal/recommended-project mydir
- The latest release of the core software will be downloaded to the mydir/web sub-directory.
If you previously downloaded the core software without using Composer, you may find later that you want or need to use Composer to manage and update dependencies. For sites created using version 8.8.0 or later of the core software the files already contain the necessary Composer configuration and you can start using Composer at any time.
If your site includes modules, themes, or profiles, that are not part of the core software it is a good idea to add them to the composer.json file in the root directory of your site.
Run the following command once for each module, theme, or profile downloaded from Drupal.org substituting
module_name for the name of the project you want to add:
composer require drupal/module_name
See below for more on managing site dependencies with Composer.
To convert a site that was created using a version of the core software prior to 8.8.0, or that was installed from a zip or tar.gz file downloaded from Drupal.org, see the instructions at Add Composer to an existing site.
Follow these steps if you are already using Composer to manage the core software, and you want to use Composer to add a contributed module or theme with its dependencies.
- Each time you want to add a contributed module or theme, determine the project’s short name. This is the last part of the URL of the project page; for example, the Geofield module, at https://www.drupal.org/project/geofield, has short name
To download the contributed module or theme, along with its external dependencies, enter the following command at the root of your site (substituting the short name of the module or theme for
composer require drupal/geofield
Follow these steps to update the files for the core software or a contributed module or theme, after having already started to manage dependencies with Composer:
- Determine the short name of the project you want to update. For the core software, it is core. For contributed modules and themes, it is the last part of the URL of the project page; for example, the Geofield module, at https://www.drupal.org/project/geofield, has short name
If you want to update to the latest stable release, use the following command, substituting the short name of the project to be updated for
composer update drupal/geofield --with-dependencies
If you need a specific version, determine how to enter the version number you want to update to. For example, for version 8.x-1.7 of a contributed module, you would enter just the 1.7, and for the core software version 8.3.1, you would enter 8.3.1. Then enter the following command at the root of your site (substituting the short name of the project for
geofieldand the correct version number):
composer require drupal/geofield:1.7
You can learn more about Composer commands by using Composer’s built-in help system. For example, to learn more about the
create-project command, enter
composer help create-project in your command window.
Adapted by Jennifer Hodgdon, Hans Fredrik Nordhaug, and Joe Shindelar at Drupalize.Me from "Using Composer to manage Drupal site dependencies", copyright 2000-2020 by the individual contributors to the Drupal Community Documentation.