Installing Drush with Composer Globally on Ubuntu 20.04

This post will help you install Drush globally on Ubuntu Desktop 20.04 and Ubuntu Server with Composer. Go ahead and launch your terminal and run the following commands.

Update Ubuntu

sudo apt update

Install PHP cli and unzip exts

sudo apt install php-cli unzip

Install Composer on Ubuntu

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

Add Latest HASH to Composer installation

HASH=`curl -sS https://composer.github.io/installer.sig`

Verify Composer HASH

echo $HASH

You should see the latest Composer HASH

Verify Composer Installation

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

You Should see

Installer verified

Set Composer Installation directory

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Check Composer Version

composer --version

Install PHP extensions for Drush

sudo apt-get update 
sudo apt install php-xml php-mbstring

Download Drupal Theming eBook Free

Install Drush with Composer

sudo composer global require drush/drush
drush --version

You Should See Latest Version of Drush

Drush Commandline Tool 10.3.1

Set Drush path

export PATH="$HOME/.composer/vendor/drush/drush:$PATH"

Download Drupal Theming eBook Free