Drush

How To Install Drush on Ubuntu 24.04 or Newer

Welcome back to the Greenhost.cloud blog! Today, we’re diving into the world of Drush, the command-line shell and scripting interface for Drupal. If you’re a Drupal developer or administrator, you know that Drush can significantly streamline your workflow, making it easier to manage your Drupal sites. In this post, we’ll walk you through the steps to install Drush on Ubuntu 24.04 or newer versions. Let’s get started!

What is Drush?

Drush is a command-line tool that allows you to manage Drupal websites efficiently. With Drush, you can perform tasks such as:

  • Clearing caches
  • Running database updates
  • Importing and exporting configuration
  • Installing and updating modules
  • And much more!

By using Drush, you can save time and increase your productivity.

Prerequisites

Before we start, ensure you have the following:

  • A server or local machine running Ubuntu 24.04 or newer.
  • Access to the terminal with sudo privileges.
  • PHP installed (Drush requires PHP 7.4 or newer).

You can check your PHP version with:

php -v

Step 1: Install Composer

Drush is best installed using Composer, the dependency manager for PHP. If you don’t have Composer installed yet, you can do so by running:

sudo apt update
sudo apt install composer

To verify the installation, check the Composer version:

composer --version

Step 2: Install Drush Globally

Now that you have Composer installed, you can install Drush globally. Run the following command in your terminal:

composer global require drush/drush

This command will download and install Drush. The installation process may take a few moments, depending on your internet speed and system performance.

Step 3: Add Drush to Your PATH

After installation, you need to ensure that Drush is in your system’s PATH. This allows you to run Drush commands from any directory in your terminal. You can do this by adding the Composer global bin directory to your PATH.

First, determine the Composer bin directory:

composer global config bin-dir --absolute

This command will return a path, typically something like /home/yourusername/.config/composer/vendor/bin.

Next, add this directory to your PATH. Open your ~/.bashrc or ~/.zshrc file (depending on your shell) using a text editor:

nano ~/.bashrc

Add the following line at the end of the file:

export PATH="$PATH:$(composer global config bin-dir --absolute)"

Save the file and exit the editor. To apply the changes, run:

source ~/.bashrc

Step 4: Verify Drush Installation

Now that you’ve installed Drush and added it to your PATH, you can verify the installation by checking the Drush version:

drush --version

If everything is set up correctly, you should see the Drush version displayed in your terminal.

Step 5: Using Drush

Congratulations! You’ve successfully installed Drush. Here are a few basic commands to get you started:

  • To clear the cache for your Drupal site: drush cr
  • To run database updates: drush updb
  • To download and enable a module: drush en module_name

Replace module_name with the name of the module you wish to install.

Conclusion

Drush is an invaluable tool for anyone working with Drupal, and installing it on Ubuntu 24.04 or newer is a straightforward process. With Drush at your fingertips, you can manage your Drupal sites more efficiently and effectively.


For more tips and tutorials, stay tuned to the Greenhost.cloud blog, where we share insights and resources to help you make the most of your cloud services and web development journey!

Drush