[SOLVED] Update Drush for Drupal 8

| | 2 min read

Everyone knows Drush is a very important tool in Drupal development, to execute things faster and to manage Drupal websites remotely. Drupal specifically built its shell function to update its configurations, managing modules, running drupal updates, etc.

For Drupal 8 older versions of Drush will not work as part of changes that Drupal 8 put forward. If you want to setup the latest version of Drush, you can follow these steps to ensure that latest version of Drush has been installed and which is compatible for Drupal 8. Else, you can update Drush using composer.

  • Open a terminal window and type:
     cd ~/
  • Download the latest version of Drush:
     php -r "readfile('http://files.drush.org/drush.phar');" > drush
  • Make the newly downloaded version executable:
     sudo chmod +x ~/drush
  • Depending on the setup, You may need to find current install path of Drush by typing:
     which drush

    It will return something like '/usr/bin/local', which can be different depending on the package manager in the system

  • Create a backup for current Drush installation:
     sudo cp /yourpath/to/install/drush /yourpath/to/install/drush_older
  • Delete the older version from your install path ('/usr/bin/local'):
     sudo rm /yourpath/to/install/drush
  • Move the newly downloaded version to the install path:
      sudo mv ~/drush /yourpath/to/install/drush
  • Initialize the newest version of Drush:
      /yourpath/to/install/drush init

Navigate to the Drupal 8 root in terminal and simply type 'drush'. If everything is fine, a list of commands will be available for you.

By following this, you can ensure that Drush has been updated to the latest version, preserving the older copy of installation, which can be used to switch between Drush versions later.

Hope this helps!