To install Drush on your system, you can follow these steps:
- Check if you have PHP installed on your system by running the command
php -v
in your terminal. If PHP is not installed, you’ll need to install it first. - Install Composer, which is a dependency manager for PHP. You can download and install Composer by following the instructions on the official Composer website: https://getcomposer.org/download/
- Once Composer is installed, you can use it to install Drush by running the following command in your terminal.
composer global require drush/drush
- This command will download and install Drush globally on your system, so you can use it from any directory in your terminal.
- Finally, add the Drush executable to your system’s PATH environment variable so you can use the
drush
command from any directory in your terminal. You can do this by adding the following line to your shell configuration file (such as~/.bashrc
or~/.zshrc
):
export PATH="$HOME/.composer/vendor/bin:$PATH"
##we use this if we install composer using installation file
OR
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
#we use this if we install composer using commands and moved composer.phar manually to bin
- Save the file, and then reload the shell configuration by running
source ~/.bashrc
orsource ~/.zshrc
in your terminal.
After completing these steps, you should be able to use the drush
command to manage your Drupal site from the command line.
How can i add drush executable globally in windows?
To add the Drush executable globally on Windows, you can follow these steps:
- Open a command prompt with administrator privileges. To do this, right-click on the Command Prompt icon and select “Run as administrator”.
- Type the following command to check if Composer is installed on your system
composer --version
- If Composer is not installed, you can download and install it from the official Composer website: https://getcomposer.org/download/
- Use Composer to install Drush globally by running the following command
composer global require drush/drush
- Once the installation is complete, you need to add the Drush executable to your system’s PATH environment variable so that you can use the
drush
command from any directory in your command prompt. To do this, follow these steps:- Click on the Start button and search for “Environment Variables”.
- Select “Edit the system environment variables”.
- Click on the “Environment Variables” button.
- In the “System variables” section, scroll down and find the “Path” variable, then click on the “Edit” button.
- Click on the “New” button and add the path to the Drush executable. The path is usually
%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
. Click on “OK” to close all windows.
- Close and reopen your command prompt, then type the
drush
command to verify that it’s working. You should see the Drush version information printed in the console.
That’s it! You have now installed Drush globally on your Windows system and added it to your system’s PATH environment variable.