Popular CLI tool renovated: what’s new in Drush 9 & 10

21 Oct 2021

Despite the availability of an administrative interface in content management systems, developers love command-line tools. A CLI enables them to do more actions or is just very convenient for tech-savvy minds. Installing modules, updating websites, clearing caches, exporting configurations, and much more is available through clear terminal commands.

In one of our previous posts, we discussed the powers of Composer for Drupal websites. This time, another CLI tool will be in the limelight. This tool’s name starts the same as Drupal, it was created exclusively for Drupal, developers respect it a lot, and it has been renovated in recent years. Let’s begin our story about Drush, its key capabilities, and its latest releases — Drush 9 and Drush 10.

Drush: useful command-line shell for Drupal websites

Drush is a command-line shell and Unix scripting interface for performing various administration and development tasks with Drupal websites. The name is a portmanteau of “Drupal Shell.” Drush uses tons of commands that interact directly with Drupal’s APIs to quickly get connected to the Drupal core, modules, themes, database, and various utilities within a Drupal website’s ecosystem. It is extensible so you can write custom commands to meet your specific needs.

This command-line shell is aimed at accelerating website development and management processes, streamlining them, and making them more convenient. With this tool, just a few clicks in the terminal are needed to fulfill a task that would take longer or often be impossible via the Drupal admin dashboard. In addition, it becomes true salvation when a website’s backend is unavailable.

Drush was originally released in 2007 as a regular Drupal module available on drupal.org. Drupal contributor Arto Bendiken created it for working with Drupal 4.7 at that time. Later, it grew into a separate project and has been getting more and more features. Received very warmly by the Drupal community, the tool still has a countless audience of developers using it. It is currently maintained by Moshe Weitzman with the help of other contributors.

“Drush is a veritable Swiss Army knife designed to make life easier for those who hack at the command prompt.”

— Arto Bendiken, the creator of Drush

Here are some examples of what Drush can do:

  • installing a Drupal website
  • installing modules and themes
  • updating the Drupal core, modules, and themes
  • enabling and disabling modules and themes
  • listing the available modules and themes
  • updating the database
  • exporting or importing the database
  • executing SQL queries
  • exporting and importing configurations
  • performing migrations
  • running Cron
  • showing Drupal Watchdog errors
  • generating dummy content
  • updating the website’s search index
  • creating, blocking, or deleting users
  • changing users’ passwords
  • editing the administrator password
  • logging in as admin via a URL
  • and much more

Major overhaul: what’s new in Drush 9

Drush 9 came as a huge rewrite of the tool. At DrupalCon Vienna 2017, when version 9 was yet an upcoming release, Moshe Weitzman gave a “Drush 9 - Lean and Modern” speech together with Greg Anderson, another maintainer of Drush and also Pantheon platform engineer. Moshe called the 9th release the first ground-up rewrite since 2008 (version 3 at the latest).

The key principles are the monumental changes in the 9th release are that it is object-oriented, Symfony-based, and in line with the Composer workflows.

“Drush has always been a pleasure to use and it does what you want with little fuss but right now we have a situation when authoring commands is a modern sort of activity, as well as all of the guts of Drush are object-oriented and really nicely decoupled.”

— Moshe Weitzman, the key maintainer of Drush

In order to bring in the best things from the Composer ecosystem, Drush 9 maintainers rebuilt the tool in a modular way with lots of Composer packages for developers to use (consolidation annotated command, consolidation site process, consolidated site aliases, and more).

With version 9, you will need to use the Composer template when starting a new Drupal project. In addition to the Drupal codebase, it will provide you with the Drush command-line tool. There is also a new Composer-based tool called Drush Launcher that you will need to put anywhere in your path.

Declaring commands became easier and more consistent. Instead of procedural .inc files, version 9’s commands are classes. The tool’s maintainers embraced a standard form called Annotated Command.

Some old commands (pm-download (dl), pm-update, make, etc.) were removed, with Composer commands as suggested best alternatives.

On the other hand, the ninth release came packed with new exciting commands for every developer to appreciate. Among them are:

  • the config-split command used for installing different sets of configuration on different environments or websites within a multisite setup (see our blog post about multisite management with partially shared configuration)
  • the generate module-standard command used for creating a new module prepopulated with basic code
  • the generate content-entity command used for creating a new Drupal content entity

Symfony Console became the tool of choice for running commands. Drush 9’s creators made a decision to move from custom CLI code to Symfony Console.

In addition, they moved the output formatters into a special open-source project. Formatters allow simple command-line tool commands to be implemented in a way that is completely independent of the Symfony Console output interfaces.

Another nice improvement is that in version 9, YAML became the default format for configuration and website aliases, so we have these in YAML instead of the old PHP-based ones.

More optimization: what’s new in Drush 10

Roughly a year after version 9, the 10th release came as the best-suited version for Drupal 8.8 that was upcoming at that time. Drush 10 talks, Moshe Weitzman said it embraced the new configuration features such as exclude API, transform API, and the config split in the core. However, it wasn’t released for new features in the first place.

“Features weren’t really the focus for Drush 10. What we did in Drush 10 primarily was remove a decade’s worth of code from Drush.”

— Moshe Weitzman, the key maintainer of Drush

Drush 9 was a combination of old and new commands, so the tool’s maintainers decided to give users a year to upgrade their commands while being able to interoperate with all the versions. Version 10 interoperates with version 9 fine but does not interoperate with the releases prior to that, said Moshe.

He called Drush 9 “extremely lean and extremely clean compared to 9.” This fact is meant to help the team maintain it for another decade and keep it a high-quality project with good test coverage for all its commands and subsystems. Moshe encouraged people to upgrade at their earliest convenience despite the lack of new features — this should give them the best level of support going forward.

In the brief release notes, Moshe Weitzman also mentions that command files written for Drush 9 are often already compatible with version 10 — you will just need to expand the constraint in your module's composer.json file.

Drush and Drupal version compatibility

All websites using a Drupal 8.4 version or higher support Drush 9 and 10. For older websites, as well as for websites on Drupal 7, you will only be able to use Drush 8. It is noteworthy that the support for Drush 8 was stopped with the release of Drupal 8.4.

There also are PHP requirements for your server, so at least PHP 5.6 is needed for using Drush 9 and at least PHP 7.1 is ok for using Drush 10. However, please note that PHP versions are getting outdated and unsupported so it’s better to upgrade to PHP 8 as a future-proof solution, which will give your website stability, security, and better performance.

Use the latest solutions!

Our team of expert Drupal developers is sure that it’s always great to use the latest versions of tools. If you need help upgrading Drush or your Drupal website itself, be sure to contact us and we will take care of a smooth upgrade process. Drop us a line!

Comments

An
Anonymous