How to install WP-CLI on Ubuntu 20.04

WP-CLI is a wordpress command line tool that helps you perform many actions you can perform in wordpress admin dashboard. It also contains commands to do things that you cannot do on the wordpress dashboard such as deleting transients. There are several ways to install WP-CLI but here, we want to look at the recommended method on how to install it.

Requirements
For this guide, you need the following requirements in your setup
• UNIX like environment. Am using Ubuntu 20.04
• PHP 5.6 or later. Am using PHP 7.4
• WordPress 5.4.1 (latest at this time)
Note that the above are not the minimum requirements for WP-CLI to work. But this is what we’ll use here as am using the latest wordpress version which works with at least PHP 5.6

Recommended Method

To install WP-CLI, follow the steps below:

  1. Download the WP-CLI file using the command below

[email protected]:~$ wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

  1. Verify the phar file downloaded above
[email protected]:~$ php wp-cli.phar –info
  1. Make the file executable
[email protected]:~$ chmod +x wp-cli.phar
  1. Move the file to a binary path
[email protected]:~$ sudo mv wp-cli.phar /usr/local/bin/wp
  1. Test if WP-CLI is installed successfully by running the command below
[email protected]:~$ wp --info

Output should be as follows

[email protected]:~$ wp --info
OS:	Linux 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64
Shell:	/bin/bash
PHP binary:	/usr/bin/php7.4
PHP version:	7.4.3
php.ini used:	/etc/php/7.4/cli/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/home/mwabini/Downloads
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.4.0

Once installed, you will occasionally need to update WP-CLI and to do so, simply run the command below:

[email protected]:~$ wp cli update

As earlier mentioned, there are other ways to install WP-CLI but which are not covered here. This include: using Git, Using Docker, Using Package Managers etc. This have been covered in the official documentation of WP-CLI located at
https://make.wordpress.org/cli/handbook/installing/

Leave a Reply

Your email address will not be published.