11.9. Using Composer and Git to Download Files

Last updated on
14 April 2025

Goal

Use Composer and/or Git to download files and dependencies in the core software, or in add-on modules and themes.

Site prerequisites

If you want to use Git or Composer, they must be installed either on a local development server or your live site. See 「概念: その他のツール」.

Steps

If you are unable to install the Git or Composer tools on your live server, after following the steps in any of the sections below on your local server, you will need to 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 files, transfer the archive to your live server, and extract it there. If you are using Composer, make sure to check for updates and additions to the following files, in the root of your installation:

  • vendor directory
  • autoload.php
  • composer.json
  • composer.lock

Using Git to download a project

Follow these steps if you want to download the development version of the core software, or of a contributed module or theme, from the project’s Git version control repository:

  1. In a command-line window, change to one level above the directory where you want the files to reside. For the core software, this would be your web root. For an add-on module, this would be the modules directory, or a sub-directory like contrib under the modules directory.
  2. Locate the page for the project that you want to download on Drupal.org; for example, https://www.drupal.org/project/drupal for the core software, or https://www.drupal.org/project/admin_toolbar for the contributed Admin Toolbar module.
  3. Click the Version control link near the top of the page, which opens up a page giving Git commands for this project.
  4. Copy the git clone command under Setting up repository for the first time, and paste it into your command line. For example, it might be:

    git clone --branch 8.2.x https://git.drupal.org/project/drupal.git
  5. This will create a directory named with the short name of the project (drupal in this example), and download the required files into that directory. If necessary, rename the directory.
  6. If you downloaded the drupal project (the core software), follow the instructions below to download its external dependencies.
  7. Later on, you can change to the created directory and run the command git pull to update the files to the latest version from the Git repository for the project.

Using Composer to download external core dependencies

Follow these steps if you downloaded the core software files using Git, which does not include the external dependencies:

  1. Change to the core software’s root directory.
  2. Run the command composer install at the command line. The external dependencies will be downloaded.

Using Composer to download the core software

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:

  1. At the command line, change to one level above the directory where you want the software to reside.
  2. Enter this command, where my_site_name is the directory you want to create:

    composer create-project drupal/drupal my_site_name

Using Composer to download a module or theme

Follow these steps if you have already downloaded the core software, and you want to use Composer to add a contributed module or theme (usually because it has external dependencies that need to be downloaded with Composer):

  1. If you have not already done so, tell Composer about the download location for contributed modules and themes, by entering this command from the root of your site installation:

    composer config repositories.drupal composer https://packages.drupal.org/8
  2. If you have not already done so, you can optionally override the default location where Composer will put downloaded modules and themes. For example, typically you would want contributed modules to go in a contrib subdirectory of the top-level modules directory, instead of the default location of modules. To make this change, edit the composer.json file at the root level in your site installation. Find the line that says "extra": {, and add these lines following that line:

    "installer-paths": {
        "modules/contrib/{$name}": ["type:drupal-module"],
        "modules/custom/{$name}": ["type:drupal-custom-module"],
        "profiles/contrib/{$name}": ["type:drupal-profile"],
        "themes/contrib/{$name}": ["type:drupal-theme"],
        "themes/custom/{$name}": ["type:drupal-custom-theme"],
        "libraries/{$name}": ["type:drupal-library"],
        "drush/{$name}": ["type:drupal-drush"]
    },
  3. 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 geofield.
  4. 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 geofield):

    composer require drupal/geofield

Using Composer to update a project’s files

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:

  1. Determine the short name of the project you want to update. For the core software, it is drupal. 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 geofield.
  2. 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 3.1.
  3. Enter the following command at the root of your site (substituting the short name of the module or theme for geofield and the correct version number):

    composer require drupal/geofield:1.7

Additional resources

Drupal.org community documentation page "Using Composer with Drupal"

Attributions

Adapted by Jennifer Hodgdon from "Using Composer with Drupal", copyright 2000-2017 by the individual contributors to the Drupal Community Documentation.

 

This page is generated from AsciiDoc source from the User Guide. To propose a change, edit the source and attach the file to a new issue in the User Guide project. PDF and e-book formats are available on the User Guide project page.

Source file: install-composer.asciidoc

Help improve this page

Page status: No known problems

You can: