Drush is an amazing tool that makes the mundane tasks of managing Drupal websites to a pleasure. Drush is a must-have tool for serious Drupal developers and Drupal maintainers.
In this blog post, I will show you how to install it on Debian based GNU/Linux distributions such as Ubuntu.
Requirements
Drush requires PHP 5.2. That mens Etch or later for Debian, and Hardy or later for Ubuntu.
As of version 2.0, Drush is a stand-alone tool. It therefore requires the command line interface (CLI) of PHP. If not already available, you can install it with following command:
sudo apt-get install php5-cliWith the requirements taken care, we can now move on to the installation itself.
Installation
Download Drush and unpack it. I prefer to put software packages that I install manually in /opt. With my wtar alias the downloading and unpacking is done in a single step:
cd /opt sudo wtar http://ftp.drupal.org/files/projects/drush-All-Versions-2.0.tar.gzPut Drush on the path by making a symbolic link from /usr/local/bin/drush to /opt/drush/drush:
sudo ln -s /opt/drush/drush /usr/local/bin/First time Drush runs, it downloads and install PEAR's Console_Table. With Drush installed as above, this must be done by root. Let us therefore invoke it the first time with sudo:
sudo drushDrush is now installed and ready to use.
Configuration
Drush requires no configuration. It works perfect out-of-box. But you should at least take a peek at the example configuration file, example.drushrc.php, to get a picture of what settings are available.
Drush looks for configuration files in several places. Settings in later found files override those in earlier. In order, the places where Drush looks are:
- Drush installation directory,
- your home directory (as .drushrc.php),
- root directory of a Drupal installation, and
- site directory of a Drupal installation.
Since the configuration files are just PHP scripts, they can contain any PHP code that you would like to have executed on startup of Drush. You could for instance call ini_set() to set the value of a PHP configuration option.
I have the configuration file /opt/drush/drushrc.php with following content:
<?php # Allow Drush to use 128 MB of memory. Use -1 for no limit. ini_set('memory_limit', '128M'); ?>This will give Drush 128 MB of memory to use. It's necessary because PHP default value is less than Drupal's need. You could of course change the memory_limit directive in /etc/php/cli/php.ini instead. But since that would effect all PHP scrips, I prefer to leave it alone.
In the root directory of every Drupal installation I also have a drushrc.php with content similar to this:
<?php // Drupal root directory to use. $options['r'] = '/srv/001/web/www'; // URI of the drupal site to use. $options['l'] = 'http://example.com/'; ?>The first line, $options['r'] = ..., tells Drush that the path to Drupal root directory. Usually, this is not necessary. Drush can derive the path from your current working directory. But without this line, symbolic links can confuse Drush.
The second line, $options['l'] = ..., tells Drush the URL of the site. This is not necessary if Drush can find the site's settings.php in sites/default. But I prefer to have the settings in a directory named after the sites domain, e.g. sites/example.com, and therefore need to tell Drush which site to work with. This is also true if you have a multisite installation.
Conclusion
Drush is almost trivial to install. Go ahead, install Drush and play around with it.
I will blog more about Drush. Next up is a blog post about how to use Drush to install a complete Drupal site.

Comments
noussh
August 7, 2009Hi,
Thanks for the article.
I don't find "ini_set('memory_limit', '128M'); " line in drushrc.php file. Are you not referring the latest drush build?
I faced a problem installing drush on mac leopard. After installing drush, when i type 'drush status' drush tries to read my page.tpl.php file content and displays on command line. After reading some forum topics from drupal.org, i changed db settings in settings.php file from 'localhost' to '127.0.0.1'. It worked.
I still have some issues like downloading, enabling or uninstalling modules with module dependancies etc.
Otherwise i really like drush, it takes lot of mundane task from us. Thanks for spreading drush.
noussh.
Thomas Barregren
August 7, 2009The `ini_set('memory_limit', '128M')` line isn't in the `example.drushrc.php` file. I added it myself. It is possible since the configuration file is just a PHP script. I've verified that the changed memory limit indeed is in effect when Drupal launches.
I've updated the blog post to be more clear on this point. Thank you for pointing out this vagueness.
Anonymous
August 10, 2009<blockquote>The second line, $options['l'] = ..., tells Drush the URL of the site. This is not necessary if Drush can find the site's settings.php in sites/default. But I prefer to have the settings in a directory named after the sites domain, e.g. sites/example.com, and therefore need to tell Drush which site to work with. This is also true if you have a multisite installation.</blockquote>
I have a question about that. If this works for multisite installations, how do you specify the urls of the other sites? You are placing this to the Drupal root, right? How do you make sure drush knows which site you want to work with?
Thomas Barregren
August 10, 2009For a single site with no `sits/default/settings.php`, as described in the text, you must tell Drush the URL of the site, so it can figure out where to find the `settings.php` file. When I wrote "This is also true if you have a multisite installation," I meant that a multisite installation also requires you to specify the URL. I should have expressed that more clearly.
For single-site installations, I specify the URL with the `$options['l']` in the `drushrc.php` of Drupals root directory. That saves my from typing `-l ...` every time I invoke Drush. For multisite installations, I am afraid you have to type `-l ...` every time, or call Drush from within the sites directory.