Moving .drush/ Folder to a Custom Location on Drupal 7

To work properly, Drush needs to create a .drush/ folder in the home directory of the user that's launching the command. If you wish to change the location of the .drush directory, you need to change the value of the HOME environment variable temporarily.

To do that, start by creating an empty module named update_drush_dir. An empty module needs only two files, an empty file named update_drush_dir.module and an .info file with basic informations:

name = Update Drush Directory
description = Update the $HOME variable each time a Drush command is launched.
core = 7.x
package = Drush

Once you have that, create a file. That's the place where Drush will look for hook implementations, a .module file would not work in this case.


 * Implements hook_drush_init().
function update_drush_dir_drush_init() {
  putenv('HOME=' . DRUPAL_ROOT . '/scripts/drush');

With this, you're pretty much set. The drush_init hook will run before each command and set the desired HOME path.

This example comes from an actual project where Drush is stored in scripts/drush/ in the webroot. We choose to move the .drush/ in this directory too.

Don't forget to change the HOME variable to a path that's relevant for you!

You can download an archive of the module here.