Once you need to update the current code follow the below steps:
Step 1: Run command:
composer update
Step 2: You need to update the current code with an update to Drupal 8 and update using custom theme and module version
core_version_requirement: ^8.9 || ^9
SO current code and modules are ready to be upgraded with Drupal 9. This way we can reduce errors.
Step 3: Create a default folder and set the file to be editable.
chmod 777 web/sites/default
find web/sites/default -name "*settings.php" -exec chmod 777 {} ;
find web/sites/default -name "*services.yml" -exec chmod 777 {} ;
Step 4: Run These Commands (This Command Edits Your Composer File to Be Upgrade Ready)
composer require drupal/core-recommended:^9 drupal/core-composer-scaffold:^9 drupal/core-project-message:^9 --update-with-dependencies --no-update
If you have drupal/core-dev installed.
composer require drupal/core-dev:^9 --dev --update-with-dependencies --no-update
Step 5: Run command
composer require "drupal/core:9.2.1 as 8.9.16" --no-update && composer update
Step 6: Run Drush updatedb command
If you face any problem with core then
Step 6.1: Run Composer outdated "drupal/*" and update this listed module into the Drupal 9 version and upgrade the appropriate custom modules and themes with Drupal 9.
Step 6.2: $config_directories['sync'] change to $settings["config_sync_directory"]
https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-8-to-drupal-9-or-later