How to Install Drush for Drupal 8

For Drupal users who are interested in adding some speed and flexibility to their workflow, this article introduces Drush, or the “Drupal shell.” Drush allows you to run scripts from the command line to manage your Drupal installation. For users who enjoy working from the shell, installing Drush is a quick, easy process that may save you a lot of time in the long run.

In this article, we will cover everything you need to know from downloading the most recent release of Drush to running your first command. And even more, you will not even need to leave the command line in order to complete this tutorial.

How to Download and Install Drush

For this installation of the Drush scripting interface, we will be working primarily on the command line. This is because Drush is a command line interface, and all of the commands you will use will need to be issued from there.

Make sure to check our article on How to log in to your VPS via SSH, which contains a link for shared servers as well.

  1. Once you are logged into your server, make sure to do a cd (change directory) command. This command, without any parameters or options, will drop you into your user’s home directory from wherever you are.
  2. You can download the most recent version of Drush from the Drupal release page. You may choose to substitute the link provided below with the most recent release available at this location.
     wget https://ftp.drupal.org/files/projects/drush-8.x-6.0-rc4.tar.gz
  3. You should now have a “tarball” (compressed file) in your home directory. Use the command below to unpack it. (Tip: start typing “drush” and tab-complete to easily avoid a typo on one of the many characters following “drush.”)
     tar zxvf drush-8.x-6.0-rc4.tar.gz
  4. Now you should be able to issue drush commands using the full path to the Drush directory, as follows:
     /home/username/drush/drush cc all

    The above command clears all Drupal caches.

Access Drush Quicker with Bash Alias

It is not necessary to use the full path to Drush in order to the scripting interface. By adding an “alias” to your bash configuration file, you can easily save yourself some time and effort. Basically, we will create a shortcut to the Drush directory, so you do not need to completely type it out each time you want to run some quick scripts. (Small savings of time amount to huge savings when compounded over the years.)

However, in order to use this scripting technique, you will need to know a little bit about your bash installation. Specifically, you must know the location of your bash configure file. This could be the .bashrc file or the .bash_profile file. By default, these files will be located in your user’s home directory.

All you need to do is edit the configuration file with your favorite text editor to add this piece of code:

 alias drush='/home/username/drush/drush'

Just make sure to substitute your cPanel username for the “username” field above.

You now know how to install Drush and run some commands. If you should get stuck along the way, you can ask Community Support a question or, leave a comment on this article.

Leave a Reply