How to use Drush to download and install Drupal modules
Posted: - Modified: | drupal, geek, tips, workOne of the best things about building websites with Drupal is that there are thousands of modules that help you quickly create functionality.
To set things up, you need to download Drush and add it to your path. For example, you might unpack it into /opt/drush
and then add the following line to your ~/.bashrc
:
PATH=/opt/drush:$PATH export PATH
Reload your ~/.bashrc
with source ~/.bashrc
, and the drush
command should become available. If you're on Microsoft Windows, it might need some more finagling. (Or you can just give up and use a virtual image of Linux to develop your Drupal websites. You'll probably end up much happier. ;) )
Once you've installed Drush, what can you do with it?
Drush is a huge time-saver. For example, I install dozens of modules in the course of building a Drupal website. Instead of copying the download link, changing to my sites/all/modules
directory, pasting the download URL into my terminal window after wget
, unpacking the file, deleting the archive, and then clicking through the various module enablement screens, I can just issue the following commands to download and enable the module.
drush dl modulename drush en -y modulename
(The -y
option means say yes to all the prompts.)
So much faster and easier. You can use these commands with several modules (module1 module2 module3), and you can use drush cli
to start a shell that's optimized for Drush.
Drush is also useful if you've screwed up your Drupal installation and you need to disable themes or modules before things can work again. In the past, I'd go into the {system}
table and carefully set the status of the offending row to 0. Now, that's just a drush dis modulename
.
Drush has a bucketload of other useful commands, and drush help
is well worth browsing. Give it a try!
18 comments
Davidis
2011-04-04T16:33:30ZThanks Sacha for this nice Drush intro.
Is there a table somewhere with the modules list and their file names?
Sacha Chua
2011-04-04T20:24:31ZNo, but Drupal and Drupal Modules list many modules. You can look at the URL for the module name when downloading it. For example, the Content Creation Kit is at http://drupal.org/project/cck, so use cck as the module name for downloading it. Some modules have submodules, so you can look in the module directory or search for all the *.info files to find out how to enable them from the command line. Hope that helps!
Mahnster
2011-04-06T12:25:05ZUm, for me anyway, it wasn't
PATH=/opt/drush;$PATH
export $PATH
but was
PATH=/opt/drush;$PATH
export PATH
note there is no $ when doing an "export" on a variable.
Sacha Chua
2011-04-07T01:43:04ZOops! Thanks for catching that. Fixing!
Lu
2011-04-29T02:10:38ZCan't believe i lived for so long without using Drush...sniff. Thanks for sharing.
Aidan McQuay
2011-04-29T03:13:15ZWe need a drush emacs major mode ;)
Hanmant A Sapkal
2011-05-18T08:55:04ZThis is good man. Thanks for sharing drush uses
drupaler
2011-07-19T14:16:45ZHi, thanks so much. Your's was the first tutorial that got drush working on my mac! It's sooooo much quicker to set up drupal now.
many thanks.
Dave
2012-03-01T10:28:17ZGood tut, just one question. How do I do this:
"To set things up, you need to download Drush and add it to your path. For example, you might unpack it into /opt/drush"
Sacha Chua
2012-03-01T20:40:35ZDave: Oooh, Drush now has even easier installation instructions. See the Drush project page.
John
2012-03-21T13:45:45ZGreat stuff. Thanks. I'm a Drupal7 newbie but Drush looks promising since I'll be needing to automate tons of stuff on the development process.
Fred Smith
2012-11-16T23:21:20ZI've been using Drupal for years and always did it via the GUI. I had problems updating to metatags beta 3 which is the first time I heard about drush as a way to get around it. The pear install simplifies the install of drush even further since it adds the path automatically.
Will have to spend some time learning how to use it.
Mike
2013-07-08T17:47:45ZHi Sacha,
I just ran across your site looking for information about Drush commands and started perusing your other post, you have a nice site... I could use some help with Drush, I've got it install and it works, but I'm completely confused about setting up an aliases file so I can upgrade one of my sites from Drupal 6 to Drupal 7... I know this post is old but Im hoping you can help.
Thank you...
sachac
2013-07-08T19:46:50ZYou don't need drush aliases if you're using the drush command on the server that the site is on (assuming you aren't running multisite?). For upgrading, you may want to copy your site to a development or staging environment, upgrade it there, and then redeploy. Lots of things are likely to break in a major version upgrade, so it's good to isolate that. =)
Mike
2013-07-09T16:54:29ZHi Sacha,
Thank you for the quick response., I do have multiple sites on the server...
So, now I'm even more confused., because when I run the Drush command site-upgrade it comes back and tells me "No target argument specified. To perform the site upgrade, define an alias record for the target site."
So, maybe I have something messed up?
Thank you again for your help....
sachac
2013-07-09T17:34:32ZOoh, hey, I didn't know about the site-upgrade command - neato! Yes, you do need to set up an alias for that one. http://www.acquia.com/blog/... has details. Looks like you need to create a new empty site that Drush will copy the upgraded site to.
Mike
2013-07-23T19:33:29ZYea, I actually found that post a while ago, but the whole process still doesn't make sense to me.., I really need someone to really spell it out for me, cause it's driving me crazy....
Thanks
Joe
2015-07-02T19:42:20ZHi Sacha,
I know this is an old thread but it helped me this week! To say 'thank you' I want to post the gist that I created , so it might help others. Here is the link https://gist.github.com/Nor...