How to Install Drush

Install Drush

Drush, the Drupal Shell, is a command-line interface (CLI) application for managing the Drupal content management system (CMS). For users who enjoy working from the shell, install Drush to save yourself a lot of time in the long run.

Drush allows you to configure modules and themes without logging into the Drupal dashboard. You can use it to manage multiple sites. Drush will even allow you to quickly backup and restore Drupal sites on your server. You can do many normal tasks within the terminal that you would normally do within the Drupal web interface.

You will need SSH access and root access for your hosting account to install Drush. You may also need to enable SSH on your server and whitelist your IP address in the server firewall.

Before getting started, check to see if Drush is already installed on your server.

composer -V

If it is installed, the following command will return the full file path to the installation.

which composer

If it’s not installed, read on to learn how to:

Ignite your online presence with cutting-edge Drupal Website Hosting. Elevate speed, security, and reliability for a seamless website experience.

Install Drush with Composer

This is the only official method for installing Drush per Drupal as Composer is already installed on InMotion Hosting servers.

  1. Log into SSH or cPanel Terminal.
  2. Add Drush to your composer.json file with the following command:
    composer require drush/drush

    Alternatively, to install Drush for all users on the server:
    composer global require drush/drush

    If you receive the error “Allow_url_fopen must be enabled,” check your selected PHP version in MultiPHP INI Editor from cPanel or WebHost Manager (WHM).

  3. Install Drush:
    composer install

Install Drush with PEAR

PHP Extension and Application Repository (PEAR) was an older method for installing Drush. Although it’s obsolete for newer versions, this may suffice for older Drush versions on private, staging environments.

For current versions of Drush for Drupal, you must use Composer as instructed above.

  1. Log into SSH or cPanel Terminal.
  2. Once connected, confirm that PEAR is on the server. You can do this by typing the following command:
    pear version
  3. Once confirmed, initialize the channel and add Drush to your PEAR channel list.
    pear channel-discover pear.drush.org
  4. After adding the channel, now we can install Drush. You should see the installation succeed similarly to the code below.
    pear install drush/drush

Install a Specific Version of Drush with PEAR

The steps above will install the most current stable version of Drush onto your server. You may, however, need a specific version of Drush installed. For example, if you are using PHP version 5.2, you cannot use Drush version 6. You will need to install version 5.9. To do this, simply enter the install command as shown below.

pear install drush/drush-5.9.0

Uninstall Drush with PEAR

Should things go wrong, or you simply decide that you no longer wish to use Drush, you can easily uninstall it from your server.

pear uninstall drush/drush

Create a Bash Alias for Faster Drush Access

It is unnecessary to use the full file path to Drush to use the scripting interface. By adding an alias to your bash configuration file, you can save yourself some more time and effort. Basically, we will create a shortcut to the Drush directory, so you do not need to completely type it out or search Bash history each time you want to run quick scripts. 

“Small savings of time amount to huge savings when compounded over the years.”

Source: Unknown

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 (Nano, Vim, Emacs, etc.) to add this piece of code:

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

Substitute the “username” field above with your cPanel username.

Should you have any further questions, be sure to take a search through our Community Forum. If you cannot find your topic there, be sure to ask the team a question and we will get back with you as soon as possible.

Learn more from our Drupal Education Channel.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

17 thoughts on “How to Install Drush

  1. It is now close to the end of 2017. Drupal 8 will have been out for two years now. I have root access to my VPS. I was able to install Composer, but for whatever reason when I follow the procedure to install drush, it does not install on the server.

    I tried this with Composer at the beginning when first working with Drupal 8 but it would not install.

    I’m going to try again soon insofar as I plan to do development directly on my server. But if there is no path to do that, it will be a big problem.

    1. You are able to implement and configure Drush and Composer on your VPS. However, its not available in shared.

  2. Hi Christopherm,

    Could you please let me know, still at present time we can not use Drush on Drupal 8 site Or something has been done in that way. I am looking for Drupall 8 hosting and looking for Drush facility as Drush solves many issues for non-technical people. Thank in Advance.

    1. Unfortunately, we do not currently have plans for implementing Drush and Composer our shared servers.

      Thank you,
      John-Paul

    1. Hello, Kingsley. Thank you for your question about Drush 8 and Composer. At the moment we have no plans to make Composer available in shared hosting.

  3. I followed the directions, but when I typed pear channel-direction pear.drush.org, I received this error message:

    Discovering channel pear.drush.org over https:// failed with message: channel-add     : temp_dir is not writable: “/root/tmp/pear” – You can change this location with                                                 “pear config-set temp_dir”

    Trying to discover channel pear.drush.org over https:// instead

    Discovery of channel “pear.drush.org” failed (channel-add: temp_dir is not writa                                                ble: “/root/tmp/pear” – You can change this location with “pear config-set temp_                                                dir”)

    Could you advise? I assume I’m on a shared hosting account that would allow this?

    1. Hello Pat,

      Unfortunately shared servers do not allow root access, which is needed to install Drush in this manner.

      Kindest Regards,
      Scott M

  4. It is not working now. Getting the below error

     

     Execution of ‘/bin/pear channel-discover pear.symfony-project.org’ returned 1: Discovering channel pear.symfony-project.org over https:// failed with message: channel-add: Cannot open “https://pear.symfony-project.org/channel.xml” (File https://pear.symfony-project.org:80/channel.xml not valid (received: HTTP/1.1 404 Not Found

     

    ))

    1. Hello Sunil,

      Sorry for the problem that you’re having. Can you provide a little more information? Is it related to Drupal? The messages we’re seeing do not appear to be Drupal-specific. It’s possible that there may be permissions problems or that you need to make sure that the files exist. The last error indicates that a particular file is not found.

      I hope this helps to answer your question, please let us know if you require any further assistance.

      Regards,
      Arnel C.

  5. Oh inmotion, how you tease with such great servers and software but no Drush on shared hosting??!!  Very close to perfect habitat for Drupal developers who have wandered the wilderness of web hosting, please reconsider Drush on shared!

    1. Hello Phoenix,

      We are definitely moving in that direction. We are currently making many improvements to our shared hosting and Drush is on the list! Unfortunately I do not yet have a time frame, but it is coming.

      Kindest Regards,
      Scott M

  6. Thank you, John-Paul!  That is clear to me now.  As VPS is not an option for me, I am looking forward to Drush being installed in shared severs before long…

  7. How can one enable or install drush on a shared-hosting server?

    According to the cited arcitle in your post, to set the root password seems possible on a shared-hosting server (to my surprise!), but the actual instruction didn’t seem to be applicable: https://www.inmotionhosting.com/support/website/ssh/root-access-faq

    I suppose there are many users (or almost all the Drupal users) who want to use Drush and I am one of them, so I am guessing it is available somewhere…?  If not, may one just install it from the source code in their home area on a shared-server?

    1. Hello Masa,

      Thank you for your drush question. While we are considering adding drush on shared servers, at this time it is not available.

      You will need a VPS, or Dedicated server to get root access, and install drush.

      If you have any additional questions, feel free to post them below.

      Thank you,
      John-Paul

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+