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.
Before getting started, check to see if Drush is already installed on your server.
If it is installed, the following command will return the full file path to the installation.
If it’s not installed, read on to learn how to:
- Install Drush with Composer
- Install Drush with PEAR
- Create a Bash Alias for Faster Drush Access
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.
- Log into SSH or cPanel Terminal.
- 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
- Install Drush:
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.
- Log into SSH or cPanel Terminal.
- Once connected, confirm that PEAR is on the server. You can do this by typing the following command:
- Once confirmed, initialize the channel and add Drush to your PEAR channel list.
pear channel-discover pear.drush.org
- 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.
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.