Last weekend we made a video that shows, hopefully, how easy it is to install Drush, the fabulously powerful command line tool that can drastically speed up developing, installing and maintaining Drupal sites. If you're worried about command line, don't fret. You can type, right? Then you can do command line!
This video covers just installing Drush. It does not get into setting up a local development environment otherwise. There are far too many ways to do that to cover here (but there are some links at the bottom of the post that might help).
The video we made seems to race by in its 2-minute running time, and it may feel like the information is going by too fast. So I've posted the same info, with some more explanation, below.
Here's the background, step by step, for your reference.
1. Download Drush
Update: While the video shows downloading the latest stable release, the project page now recommends you download the latest HEAD version. Update 29 March 2010: Drush 3 has reached release candidate stage, so at this point it's probably best to use the latest stable release after all. —LS]
Get it at http://drupal.org/project/drush. Drush works for every version of Drupal, so just find the latest version and download it.
Put the tarball into your working folder. Ideally this is a folder in your home directory. Some people use their "sites" folder for development. I created on my computer in my home directory a working folder called "dev".
Double-click on the tarball to open it up. When you go into the drush folder, you'll see a number of files, including the README.txt file. Read it!
2. Make Drush Executable
Now we venture into the command line. I hope that doesn't vex you, because Drush is a command line tool.
Open your Terminal. This opens up to your "home" directory, which corresponds to the Finder folder that bears your Mac username.
You will want to type the command here:
chmod u+x /path/to/drush/drush
(replacing "/path/to/" with the actual path relative to your home directory). So in my case, with Drush residing in the "dev" folder:
chmod u+x dev/drush/drush
Now that you've made
drush executable, you want to set things up so you actually can execute the
drush command outside of the actual Drush folder (such as in your working folder for the site you're building). So....
3. Create an Alias
This part may seem a bit mysterious if the Terminal stuff is new to you, but it's really quite simple. We will be adding to your "bash profile" file the path to the
drush command so that you can run the
drush command from anywhere in your filesystem.
Find your bash profile file using the Terminal in your "home" directory.
If you're not there, go ahead and enter on the command line:
The bash profile files are hidden from normal view, so to see what files you have in your home directory, enter this command:
You get a list of all the files in that folder. (The "hidden" files start with a dot ".") Look for one of these files:
Any one will do, so just pick an existing file. (For me, it was
Edit the file in the nano editor, the really simple, old school text editor that comes with Unix. Just enter
nano [filename]. For me, that means:
This takes you into the editor, and might be looking at one or two lines of code. Cursor down to the end of the file and make sure you're on a new line, and add:
replacing the "/path/to/" part with the actual path — but this time it needs to be relative to the system root. Now, remember that shortcut to the "home" directory above? Now's the time to use that.
Now save the file using
<enter>. Now you're back at your Terminal prompt.
Now all you need to do is reload the updated bash profile using
source [filename]. In my case:
Yes, I know I said it was three steps. But this is testing, and you don't want to skip testing, do you? To test, simply type:
You should get a long list of available Drush commands. You're done! (Or rather, now you can get started!)
You'll want to dive in and experience Drush Power™! So here are pages you will want to explore.
- The main Drush documentation page (bookmark this) has a list of the basic drush commands.
Pay special attention to the examples at the bottom. I found, for example, that if a drush command wasn't working, pointing to the actual uri for that Drupal instance helped Drush find the appropriate database. Also remember that not all modules are covered in the project name. For example, CCK contains a lot of modules, so you can "dl CCK" but you cannot "en CCK".
- Using Drush to synchronize and deploy sites looks to be one extremely powerful use case for Drush. This is amazing. Anything that makes deployment easier is a big plus in my book!
- Drush Make, an extension to Drush that can create a ready-to-use Drupal site, pulling sources from various locations. It does this by parsing a flat text file (similar to a drupal .info file) and downloading the sources it describes. In practical terms, this means that it is possible to distribute a complicated Drupal distribution as a single text file.
More helpful references on Drush, its installation, its power, and more
- Development Seed's many many posts on Drush are always interesting. If you're interested in Ægir, this is where you want to look.
- Morten "the King of Denmark" Birch Heide-jørgensen's step-by-step post on setting up a local development environment, including installing Drush.
- Lin Clark's video walking through getting started with Drush and Drupal 7.
- Drupal modules that have commands for Drush. This could be very interesting, seeing where this goes.
- RSS feed of Drush releases (because your Available Updates report in Drupal won't tell you about Drush updates that are released).
Hope this is helpful!