How To Install WP-CLI on Ubuntu 22.04 LTS
In this tutorial, we will show you how to install WP-CLI on Ubuntu 22.04 LTS. For those of you who didn’t know, WP-CLI is a command-line interface for WordPress, a popular content management system (CMS) used to build and manage websites. WP-CLI provides a set of commands that simplify tasks such as managing plugins, updating themes, and managing users.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the WP-CLI command-line interface for WordPress on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for WP-CLI.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install WP-CLI on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade sudo apt install wget apt-transport-https gnupg2 software-properties-common
Step 2. Installing WP-CLI on Ubuntu 22.04.
- Method 1. Installing WP-CLI using Package Manager Ubuntu √
By default, WP-CLI is available on Ubuntu 22.04 base repository. Now run the following command below to install the latest version of the WP-CLI to your Ubuntu system:
sudo apt install wp-cli
- Method 2. Installing WP-CLI from the Source Code √
First, download wp-cli.phar
using wget
command:
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Next, make the WP-CLI package executable, and run the following command:
chmod +x wp-cli.phar
Move it to somewhere in your PATH. For example:
sudo mv wp-cli.phar /usr/local/bin/wp
To verify the installation, run the following command:
wp --info
Output:
OS: Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Dec 16 11:20:35 UTC 2021 x86_64 Shell: /usr/bin/zsh PHP binary: /usr/bin/php8.1 PHP version: 8.1.0 php.ini used: /etc/php/8.1/cli/php.ini MySQL binary: /usr/bin/mysql MySQL version: mysql Ver 8.0.27-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu)) SQL modes: WP-CLI root dir: /home/wp-cli/ WP-CLI vendor dir: /home/wp-cli/vendor WP_CLI phar path: WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/ WP-CLI global config: WP-CLI project config: /home/wp-cli/wp-cli.yml WP-CLI version: 2.7.1
Step 3. Updating WP-CLI.
If there is a core update available, you can update the WordPress install using the following command below:
wp core update
Step 4. WP-CLI Commands Examples.
Here’s a table that summarizes some of the WP-CLI commands with examples:
WP-CLI Command | Example |
---|---|
wp core download |
wp core download |
wp core install |
wp core install --url=example.com --title="Example Site" --admin_user=admin --admin_password=password --admin_email=admin@example.com |
wp plugin install |
wp plugin install jetpack |
wp theme install |
wp theme install twentytwenty |
wp post create |
wp post create --post_type=page --post_status=publish --post_title="Example Page" --post_content="This is an example page." |
wp user create |
wp user create example_user example@your-domain.com --role=administrator |
wp option update |
wp option update blogdescription "An example WordPress site" |
wp plugin deactivate |
wp plugin deactivate jetpack |
wp theme switch |
wp theme switch twentytwenty |
wp post list |
wp post list --post_type=page --posts_per_page=5 --order=asc |
Congratulations! You have successfully installed WP-CLI. Thanks for using this tutorial for installing the WP-CLI command-line interface for WordPress on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official WP-CLI website.