How to have multiple Drush versions installed

Having multiple versions of Drush installed on your system can be useful if you need to work with different Drupal versions that require different versions of Drush. Here's how you can install and manage multiple versions of Drush:

  1. Install Drush using a package manager: If you're using a package manager like Homebrew on macOS or apt-get on Ubuntu, you can install multiple versions of Drush by specifying the version number. For example, to install Drush 9 on Ubuntu, you can use the following command:
    sudo apt-get install drush9
    To install Drush 10, you can use the following command:
    sudo apt-get install drush10
  2. Install Drush using Composer: If you're using Composer to manage your Drupal projects, you can install multiple versions of Drush as dependencies of your project. To install Drush 9, you can add the following line to your composer.json file:
    	"require": {
    	    "drush/drush": "^9.0"
    	}
    To install Drush 10, you can add the following line:
    "require": {
        "drush/drush": "^10.0"
    }
    
    You can then install the required version of Drush by running 'composer install'.
     
  3. Use aliases: Another way to manage multiple versions of Drush is to use aliases. You can create aliases for different versions of Drush in your shell configuration file (e.g. .bashrc or .zshrc). For example, you can create aliases for Drush 9 and Drush 10 as follows:
     
    	alias drush9='~/.composer/vendor/bin/drush'
    
    	alias drush10='~/.config/composer/vendor/drush/drush/drush'
    

You can then run the desired version of Drush by using the corresponding alias. For example, to run Drush 9, you can use the drush9 command.

By using one or more of these methods, you can have multiple versions of Drush installed and easily switch between them as needed.