This article is updated on October 19th, 2021 to reflect recent developments on this subject.
Composer is a great tool for Drupal and in general PHP developers, but in some cases, it might take some effort to accomplish what you want. I tried to install Drupal 9 (dev version) and Drush 10 today and here's what I had to do to make it work.
I'm using Docker4Drupal for my local environment, so the first step was to configure a new project according to the documentation. After that, I just cloned Drupal 9 using GIT and executed composer install. Starting with Drupal 8.8, we have the template projects provided directly by Drupal core so we don't have to use drupal-composer/drupal-project anymore.
Now the fun part. To install Drush 10 in theory you just have to execute:
composer require drush/drush:^10
But if you do that you will see the following error:
That looks scary!
Fortunately, fixing it is easy. This is happening because of symfony/var-dumper component. Drupal 9 has the following constraint:
"symfony/var-dumper": "^4.3|^5.0"
while Drush 10 has this one:
"symfony/var-dumper": "^3.4 || ^4.0",
Running composer install after you clone Drupal core will install version v5.0.0 of symfony/var-dumper. That's not good because Drush is not supporting that version.
The fix is to find the common ground and add the following line to the composer.json file:
"symfony/var-dumper": "^4.4"
Version 4.x is supported by both Drupal 9 and Drush 10, so you will now be able to install the latest version of Drush. After adding this line first downgrade var-dumper and then install Drush:
composer update symfony/var-dumper
composer require drush/drush:^10
Yay!
Note: This will probably be fixed soon by Drush using the same versions of symfony/var-dumper as Drupal, but let this blog post be of educational value.
You can also read my blog posts on How to upgrade Drupal 8 to 9 and Upgrading to Drupal 9 and Composer 2.
October 19th, 2021 update
Drupal 9 is stable and installing Drush is no longer an issue. Drush 10 can be installed on the latest Drupal 9.3 development version, and also the latest Drush 11.x-dev version can be installed as well.