How to Install Drush

Install Drush
Drush logo

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.

Share this Article
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