Installing Drush on *nix

Video loading...

  • 0:00
    [robotic voice] Drupalize me. [Drupalize.me - Learn Drupal]
  • 0:04
  • 0:06
    [Installing Drush on *nix - With Addison Berry]
  • 0:12
    Hi there. In this video we're going to be looking at how to install
  • 0:16
    the Drupal utility called Drush,
  • 0:19
    which you can find on drupal.org at drupal.org/project/drush.
  • 0:25
    This is a command-line tool, which is really, really handy,
  • 0:29
    but it requires a little extra thought and work when installing
  • 0:33
    than a typical Drupal project does.
  • 0:35
    So let's take a look at what we need to do.
  • 0:38
    Before we actually dive into the installation itself,
  • 0:41
    let's take a moment to make sure we have the requirements that we need.
  • 0:45
    This is covering only installation on *nix systems like Linux, Unix, or Mac OSX.
  • 0:50
    We're not going to talk about Windows in this video;
  • 0:52
    we'll have another one for that one.
  • 0:54
    And we want to make sure that we have PHP at least at 5.2
  • 0:58
    with a command-line interface.
  • 1:00
    And, of course, you also will need access to an actual command line.
  • 1:03
    It's a command-line tool.
  • 1:05
    So what we're going to do is real quickly I just want to check and make sure
  • 1:08
    that my PHP version is correct.
  • 1:11
    So I'm going to open up terminal, which is my command line on--
  • 1:14
    I'm on a Mac--and I'm going to type in php dash v to get the version information
  • 1:20
    for my PHP that I'm running from the command line.
  • 1:23
    And you can see it tells me the version, the full version number,
  • 1:26
    so I definitely have 5.2, and it also indicates that it is CLI,
  • 1:31
    but I wouldn't have been able to access it without that.
  • 1:33
    So I'm good with my PHP.
  • 1:36
    Obviously I have access to the command line.
  • 1:38
    And I am on a Mac for this example.
  • 1:41
    Now, these are the 3 basic steps for installing Drush,
  • 1:45
    and we'll run through them and then we'll break it down step by step through the video.
  • 1:49
    First we need to actually get Drush, so we need to download it from drupal.org.
  • 1:53
    Then you need to make it executable.
  • 1:55
    This is actually a script that you're going to be running,
  • 1:57
    so it has to be able--your system has to be able to execute the script
  • 2:01
    in order for it to work.
  • 2:02
    And then we're going to talk about the Drush path so that you can
  • 2:06
    run the Drush command from anywhere on your system
  • 2:09
    without having to know the full path to where this actual script sits.
  • 2:13
    We kind of want to make it universally available on our computers.
  • 2:17
    Before we get started, I just want to show you how you can find
  • 2:20
    all of these installation instructions yourself easily on-line.
  • 2:24
    If you go to the Drush project page, there's a link to Drush.ws,
  • 2:28
    and they have an FAQ there that has a link to the readme.txt file
  • 2:34
    that is actually packaged with Drush when you download it.
  • 2:38
    But you can read it online by going to the Drush.ws site.
  • 2:42
    It has the requirements we just talked about,
  • 2:44
    the installation steps, and in addition--it's quite a large file--
  • 2:48
    if you keep scrolling down it has additional things for like if you're
  • 2:51
    configuring it on MAMP and other AMP stacks.
  • 2:54
    So there are different configurations for different set-ups.
  • 2:58
    There is a lot of information in this file.
  • 3:00
    Okay. So let's do step 1, download Drush.
  • 3:04
    There are several ways that you can download Drush.
  • 3:06
    It's all going to come from drupal.org's project page.
  • 3:09
    You can get the actual tarball or zip file
  • 3:13
    from the project page, and you can do that either by clicking--
  • 3:16
    like, you know, if you just went to a site and click the download,
  • 3:19
    or you can use FTP or wget on the command line ,
  • 3:25
    so you don't have to do it through a graphical user interface.
  • 3:28
    Or, you can also--if you have Git you use Git to just get a clone of Drush,
  • 3:32
    and then you can easily update by using Git, which is a really handy way to do this.
  • 3:37
    What we're going to look at here is we're going to actually use the command line
  • 3:42
    to download the tarball--do it that way.
  • 3:45
    It's a command-line tool; you're going to need to use command line anyway,
  • 3:47
    so you might as well start early.
  • 3:51
    So I'm going to start off on the drupal.org project page for Drush,
  • 3:54
    and I'm going to point out a few things before we get to the download.
  • 3:57
    One is that you can see that Drush is independent of Drupal version,
  • 4:01
    so you can really sort of download any of them and it's going to work for you.
  • 4:05
    If you come now to the download,
  • 4:07
    you'll see there is a 7x-4.5, so 4.5 is actually the version of Drush, the 4 series.
  • 4:14
    There's a 4x and a 5x for development; those are two different versions.
  • 4:19
    We're going to go ahead and just stick with the official recommended release here,
  • 4:23
    and you can see there is a tarball and a zip.
  • 4:25
    You can download whichever one floats your boat.
  • 4:28
    The other way that you can get a download of Drush
  • 4:32
    is if you click on the version control tab on the project page
  • 4:35
    there is information on how you can pick your version,
  • 4:39
    and again we'll just go with--you know--I'll just show you the normal version that you should get.
  • 4:44
    You'll see that there's a command; you can just copy and paste this Git command.
  • 4:49
    You need to have Git installed on your computer for this to work,
  • 4:52
    but if you do it's a really quick, simple way to get a copy.
  • 4:55
    We're going to do our download by getting the tarball,
  • 5:00
    but I'm going to get it from command line rather than clicking and saving it.
  • 5:03
    So I'm going to copy the link location; I've right-clicked on that link
  • 5:06
    and got the actual link location for where that download is.
  • 5:10
    And now I'm going to go back to my terminal and use that to download it from the command line.
  • 5:14
    Now I'm going to--this is my home directory,
  • 5:18
    and you'll see I have a Drupal folder in here,
  • 5:22
    so that's where I'm going to put my Drush download.
  • 5:24
    You can put Drush anywhere you want on your system that you have access to.
  • 5:28
    It doesn't matter.
  • 5:30
    You just need to pick a place that makes sense to you.
  • 5:33
    So I'm going to use the FTP command.
  • 5:35
    You can also use wget on a lot of systems--on Linux systems.
  • 5:39
    Mac OSX doesn't have wget by default,
  • 5:44
    but it does have FTP, and so I'm going to use FTP.
  • 5:47
    When I paste this URL in, you can see it's using an FTP server on drupal.org.
  • 5:52
    So I can use that from the command line to grab this file,
  • 5:56
    so I'll go ahead and run that.
  • 5:59
    And now if we look in here you'll see I have a tarball that's been downloaded.
  • 6:03
    And now I just need to uncompress this.
  • 6:07
    Since it's a tarball, I need to use the tar command.
  • 6:11
    If it was a zip I could use the unzip command,
  • 6:15
    which--get whichever one you are more comfortable with.
  • 6:17
    So I'm going to extract this tarball, and I'll run that command.
  • 6:23
    And you can see it opened everything up and put it into a nice, handy Drush folder for me.
  • 6:29
    So let me clear some of this stuff out.
  • 6:31
    You can see--so I have my Drush folder and then I have that tarball in there.
  • 6:36
    That's all I need to do to download Drush and get ready to play around.
  • 6:42
    If we go into the Drush folder, we'll take a look at the files.
  • 6:47
    You can see the actual Drush script is located in here, just called drush.
  • 6:52
    And there is also that readme.txt file as well, so once you've downloaded Drush
  • 6:58
    you can read that entire readme file, and you have all the installation instructions.
  • 7:02
    So if I just open that up here real quickly, you can see here are the same
  • 7:05
    installation instructions we saw on the online version of it.
  • 7:10
    So you have access to that stuff right here on your local machine now.
  • 7:14
    Okay, so now that we have it downloaded,
  • 7:17
    we need to make the Drush script executable.
  • 7:21
    It's a script, so our computer needs to have permissions in order to
  • 7:24
    actually run the script in order for it to work for us.
  • 7:27
    So here's the typical command; we need to chmod the Drush script.
  • 7:32
    You may or may not need sudo depending on your user permissions for doing these things.
  • 7:36
    But we do need to chmod and add executable rights to the Drush script,
  • 7:41
    so let's hop back over to terminal and see how that looks and works.
  • 7:46
    I'm going to do an LSAL so we can see all the permissions on the files in my Drush folder here.
  • 7:53
    And you'll see here's the Drush script,
  • 7:55
    and you can see the permissions that are listed all the way to the left.
  • 7:59
    And it already has the executable.
  • 8:01
    You can see there's an R, W, and X; that's read, write, and executable permissions.
  • 8:06
    So for the user it already has read, write, and executable.
  • 8:11
    So this script is actually already capable of running,
  • 8:15
    but you need to double check that, and if you don't have the executable on there,
  • 8:19
    what you need to do is do a chmod command to add it.
  • 8:22
    So we would chmod, and then for the user we want to add executable,
  • 8:28
    so that's u+x (user add executable) and then the name of the file, which is drush.
  • 8:34
    I don't need to actually run this myself because it already is executable,
  • 8:38
    but if you do run this command, double check it again
  • 8:42
    to make sure that it is actually executable, and you should be good to go.
  • 8:47
    Very important step that some people miss and makes them a little crazy.
  • 8:51
    Let me clear this screen out here.
  • 8:54
    I just want to real quickly show that this actually works,
  • 8:58
    so you can see I'm in my drush folder, which is where the drush script lives.
  • 9:04
    And I can run the script by doing dot slash drush (./drush).
  • 9:09
    I have to say where the file is, and you can see Drush is working.
  • 9:13
    So dot slash simply means in this directory, run the drush script.
  • 9:17
    And I did, and I'm getting help text from Drush, so it's working, which is awesome.
  • 9:23
    So we are pretty much there, except that--let's talk about paths.
  • 9:29
    I can type Drush currently and use Drush inside of that directory,
  • 9:35
    inside my Drupal Drush directory.
  • 9:37
    But I can't just go anywhere willy-nilly and type the word "drush" and have it work,
  • 9:43
    and there are two ways that we can add this.
  • 9:46
    And this is just one of those things that's just super convenient,
  • 9:49
    so you might as well do it.
  • 9:50
    And we can either create a symbolic link or we can add the drush path to our path variable
  • 9:56
    on our computer.
  • 9:58
    We're going to talk about what both of those mean
  • 9:59
    and how to do both of those so that you don't drive yourself crazy
  • 10:04
    having to type full paths out everywhere.
  • 10:07
    Okay. So, back on the command line.
  • 10:10
    I'm going to just go to my home directory,
  • 10:13
    so you can see I'm just--I'm not in the drush directory anymore.
  • 10:15
    I'm just in my home directory.
  • 10:17
    If I type the word "drush" nothing happens.
  • 10:19
    If I do ./drush, nothing happens because the script isn't located here
  • 10:23
    and it doesn't know where to find it.
  • 10:26
    So if I'm not actually in the drush directory, I'm kind of limited.
  • 10:31
    The way that I could run it from anywhere is to type the entire path to the drush script,
  • 10:39
    anytime I wanted to use it.
  • 10:40
    So I could type this out.
  • 10:42
    So I'm in /Users/add1sun/drupal/drush/drush
  • 10:48
    and if I type that out it works because I'm telling my computer
  • 10:51
    the entire system to where it needs to go,
  • 10:53
    but you would have to type that out every single time you wanted to use drush.
  • 10:56
    That is a pain.
  • 10:59
    So we're going to make it so that we can just type the word drush and be done with it.
  • 11:03
    To understand what we're doing here, we need to talk about paths.
  • 11:06
    Your system has a path variable, which is a list of all of the paths
  • 11:10
    that it will execute scripts from, essentially.
  • 11:14
    So if you echo $PATH, you can see what your current settings are,
  • 11:18
    and you see there are a bunch of paths separated by colons.
  • 11:22
    The most common ones for our use case here
  • 11:24
    where you would want to put your script so it will run is user/bin or user/local/bin.
  • 11:30
    They already exist, and I can just sort of re-use that.
  • 11:33
    But instead of actually physically moving my drush script
  • 11:36
    into one of those directories,
  • 11:38
    I can use a symlink so that the computer thinks that the script is there
  • 11:42
    and will therefore execute it without me having to move things around.
  • 11:46
    I want to keep them organized the way I want to.
  • 11:48
    So I'm going to do a symlink, one simple command here,
  • 11:52
    so it's link dash s, for symlink or soft,
  • 11:55
    and then I need to put the path to my script--to the drush script.
  • 12:01
    So the full path here is /Users/add1sun/drupal/drush.
  • 12:05
    Drush is the folder. Remember there is a folder that holds the drush script.
  • 12:09
    And then there is a drush script inside of that,
  • 12:12
    and I need to put the actual script I'm pointing to, not the folder
  • 12:16
    because a folder's not executable; it won't do anything.
  • 12:18
    So then slash drush for the script name. So drush/drush.
  • 12:21
    It looks weird, but that's what we need to do.
  • 12:24
    And then where I want it to be, where I want it to be located,
  • 12:29
    which is /user/local/bin/drush.
  • 12:31
    I'll type in the drush command name there.
  • 12:36
    You know--you could put in something silly like dr, but I'm going to use drush
  • 12:40
    so I know which command I'm talking about.
  • 12:43
    And when I do that, now if I type the word "drush"
  • 12:47
    the command will execute.
  • 12:50
    It knows it's now going back, following that symlink and going back
  • 12:53
    to the actual drush script and running it, and so it works great, which is awesome.
  • 12:58
    Now the other way of approaching this is to update our path variable ourselves,
  • 13:07
    like actually add the drush path to that path variable.
  • 13:11
    So to see how this works,
  • 13:13
    I'm going to just remove the symlink so we can tell when it's working or not working.
  • 13:18
    And now if I do drush it won't work anymore, so I'm back to where I was.
  • 13:22
    Now what I want to do is actually edit my path variable.
  • 13:26
    You do this in different files on different systems,
  • 13:30
    but normally you have like a user file where you have user configurations for your shell,
  • 13:39
    and that's where you would set your path, your custom path stuff.
  • 13:43
    I'm currently in my home directory,
  • 13:46
    and if I look at all the files including the hidden files,
  • 13:48
    the ones that start with a dot in front of them,
  • 13:52
    the bash profile is the file that I have my custom path configuration in.
  • 13:57
    So I'm going to edit my bash profile, whichever file you need to
  • 14:02
    on your system is where you would do this.
  • 14:05
    Use whatever editor you want to.
  • 14:06
    I use vi.
  • 14:09
    And if this file doesn't exist for your system, go ahead and create it
  • 14:11
    in your user directory.
  • 14:14
    And you can just add the information that you need.
  • 14:17
    So this is the line where I'm adding paths.
  • 14:21
    You can see I'm actually adding some paths from MAMP in here
  • 14:24
    that I wanted to have executable without having to type all that stuff in.
  • 14:28
    So I've actually already added some things,
  • 14:31
    and then I pre-pended that to the existing path variables.
  • 14:34
    That's very important. You don't want to override, you want to add to.
  • 14:37
    So make sure you have the path variable at the end there, as well.
  • 14:40
    The colons are important as well; that separates each path.
  • 14:43
    You don't want it to all run together or it won't work.
  • 14:46
    So I'm going to insert a colon to start a new section for a new path I'm entering.
  • 14:51
    And then the path that I need to enter is my drush folder.
  • 14:56
    Again, this is not the script. This is the container that holds things that I want to execute.
  • 15:02
    So I can just put the folder in this, whereas in the symlink I put the script.
  • 15:07
    It's a fine distinction but important.
  • 15:09
    Once I've added this into my path variable,
  • 15:13
    using this syntax here to make sure that system knows about it,
  • 15:19
    I'm going to go ahead and save that.
  • 15:22
    And if I try to run the command right now,
  • 15:27
    it's actually not going to work yet,
  • 15:30
    and that's because whenever you update these kinds of profiles
  • 15:34
    shell profiles, you need to restart a session on the shell
  • 15:38
    in order for it to pick up the changes you have done.
  • 15:42
    So I'm going to close my window and open it up again.
  • 15:46
    And now that I've started a new shell session, now the changes are in there
  • 15:50
    and now it works.
  • 15:52
    So that's something also that tends to hang people up a little bit.
  • 15:55
    But now it's working.
  • 15:57
    I can type the word "drush" from anywhere in the system,
  • 16:01
    and it will execute it.
  • 16:02
    And now I'm ready to go nuts using this wonderful, wonderful tool called Drush.
  • 16:08
    And we have more videos to talk about the specifics of actually using Drush.
  • 16:13
    So now that you're up and running, time to go play.
  • 16:17
    [drupalize.me] [Learn Drupal]

Installing Drush on *nix

Loading...

Please note: There have been updates to Drush since this video was recorded. You can learn more about installing newer versions of Drush in the blog post Upgrading Drush to work with Drupal 8. The newest version of Drush requires Composer for the installation process. If you need help getting Composer figured out, you can watch the Wonderful World of Composer video tutorial.

In this video we walk through the steps to install Drush on *nix system (i.e. Linux, Unix, or Mac OS X). Drush is not a normal Drupal project and the installation and set up is quite different than for a module. We cover requirements and downloading, then make sure Drush is executable and in our system $PATH variable so we can use Drush from any directory.

One of our members, David, offered the following tip:
I had an issue with OSX Lion and the new drush 5.0... When using the drush command the following error occurred:
/usr/bin/env: bad interpreter: Operation not permitted
This is due to Lion Quarantining the files as they are from the internet. Remove the quarantine attribute with:
xattr -d com.apple.quarantine drush
The Drush command should work now! I hope I saved someone the 2 hours of anguish this caused me.

Additional resources:
There are no resources for this video, if you believe there should be please contact us.

Average review

1
Average: 1 (2 votes)

Reviews

1

This video is outdated. Composer is needed to install drush and I haven't got a clue on how to get that working.

I was so looking forward to finally be able to use drush and I still have to work without it. Please record a new video asap!

1

Absolutely agree with the previous comment. Composer is needed and I can't do anything with an outdated tutorial like this.

What's possibly worse is having to listen to the theme song for this site at the top of every. single. video.