User login

Drush feature request: install a module (or theme) into an arbitrarily specified directory

The ability to use the Drush Package Manager (drush pm) to install a module in an arbitrarily specified directory doesn't presently exist.

My use case is to install modules into an installation profile, and not only that but a 'contrib' directory in the modules directory for that installation profile. However, people who want to install modules to subdirectories in the more normal sites/all/modules (or sites/example/modules) will need to be able to set their path also. Moreover, someone who wants to use sites/default/modules instead of sites/all/modules, or sites/all/modules even though they have a sites/example/modules in use, need to be able to set the path for Drush PM to look for installing and upgrading.

Finally, it appears that being able to set the directory is the only substantive thing stopping us from using Drush to install themes, too.

Below are excerpts from drush_pm.module that relate to the installation location, as regards the install command at least:

 * Implementation of hook_help().
function drush_pm_help($section) {
// ...
  switch ($section) {
    case 'drush:pm install':
      return t("Usage: drush [options] pm install <package_1> <package_2> ...
<package_n> is the short name of a project hosted on,
or the short name and the version number (Drupal major version is optional).
e.g. project, project-5.x-1.0, project-1.0, project-1.x-dev, project-1.1-rc1
So far, only modules are supported.\n
The modules will be installed into a site specific modules directory if one
exists, otherwise sites/all/modules is used.
After installing, you still have to activate on the normal module
administration page\n\n". $handler);
// ...

 * Implementation of hook_drush_command().
function drush_pm_drush_command() {
  $items['pm install'] = array(
    'callback' => 'drush_pm_install_package',
    'description' => 'Install one or more modules'
// ...

 * Command callback. Installs one or more packages (so far only modules).
function drush_pm_install_package() {
  $projects = func_get_args();
  if (empty($projects)) {
    drush_die(t("No project specified.\n\nRun drush help pm install for more information."));
  // Parse out project name and version
  $projects = drush_pm_parse_package_name($projects);
  // If a URI is provided then we install to that specific site, otherwise we install to sites/all/modules
  if (DRUSH_URI) {
    $path = conf_path();
    $modulepath = DRUSH_DRUPAL_ROOT .'/'. $path .'/modules/';
  if (!isset($modulepath) || !file_exists($modulepath)) {
    $modulepath = DRUSH_DRUPAL_ROOT .'/sites/all/modules/';
// ...

It would be fairly easy to hack in the ability to, say, notice if the first argument passed in after pm install is a "-p" and if so treat the second argument as the path to install to, overriding the two approaches to constructing the module path above.

A proper solution, however, would work for pm update, pm info, and pm status as well. I'm not sure if that means it should be defined in the drush command flags (the [options] mentioned in the help) or if a new place to defined flags after the pm would have to be created for the package manager module.


Searched words: 
drush pm install module in particular directory drush pm install module in different directory Drupal Shell Package Manager


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.