How to Install WP-CLI on Ubuntu 26.04, 24.04 and 22.04

Install WP-CLI on Ubuntu 26.04, 24.04 and 22.04 with signed PHAR, verify the download, run WordPress commands, and manage updates or removal.

PublishedAuthorJoshua JamesRead time8 minGuide typeUbuntu

Managing WordPress from a browser gets slow when you are updating plugins, checking core versions, or repeating the same maintenance task across several Ubuntu sites. The practical way to install WP-CLI on Ubuntu is the official PHAR build, which gives you the current wp command without waiting for an Ubuntu archive package.

A system-wide install in /usr/local/bin/wp works well for administrators who manage several sites from one account. The same setup supports local WordPress files, existing Ubuntu web roots, optional WP-CLI packages, and remote SSH targets.

Install WP-CLI on Ubuntu

WP-CLI’s official installation guide recommends downloading the PHAR file, making it executable, and placing it on your PATH. Ubuntu does not currently publish a normal wp-cli package in its supported LTS archives, and the upstream WP-CLI builds repository publishes direct package files rather than an Ubuntu APT repository with automatic updates.

The PHAR path is the cleanest Ubuntu default because WP-CLI can update itself with wp cli update, while Ubuntu still manages the PHP CLI runtime underneath it.

Update Ubuntu and Install WP-CLI Prerequisites

Refresh APT metadata before installing PHP CLI and the download tools:

sudo apt update

These commands use sudo for package installation and for placing wp in a system path. If your account cannot use sudo yet, use a root shell or follow the guide to add a new user to sudoers on Ubuntu.

Install the packages WP-CLI needs for the recommended install flow. php-cli runs the PHAR file, php-zip lets WP-CLI extract WordPress release archives for commands such as wp core download, curl downloads the release files, ca-certificates keeps HTTPS validation current, and gnupg verifies the upstream signature.

sudo apt install php-cli php-zip curl ca-certificates gnupg

The curl command guide explains the common transfer flags if you want more detail about -f, -L, and saved output files.

Confirm that PHP is available from your terminal:

php --version

On Ubuntu 26.04, relevant output begins with the packaged PHP CLI branch:

PHP 8.5.4 (cli)

Different Ubuntu LTS releases report different PHP branches, but WP-CLI currently requires PHP 7.2.24 or newer, so the default php-cli package on supported Ubuntu releases is sufficient.

Download WP-CLI on Ubuntu

Download the stable PHAR file, its detached signature, and the WP-CLI release signing key into your current directory. The -f flag makes curl fail on HTTP errors, -sS keeps successful downloads quiet while still printing errors, -L follows redirects, and -o saves each file with the expected name.

curl -fsSLo wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
curl -fsSLo wp-cli.phar.asc https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.asc
curl -fsSLo wp-cli.pgp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/wp-cli.pgp

The first file is the executable WP-CLI PHAR. The .asc file and wp-cli.pgp key are used only for the optional but recommended verification step from the WP-CLI download verification guide.

Verify the WP-CLI Download

Use a temporary GnuPG home so the verification does not add the WP-CLI key to your personal keyring. Continue only when the fingerprint and good-signature line match.

tmp_gnupg=$(mktemp -d)
GNUPGHOME="$tmp_gnupg" gpg --import wp-cli.pgp
GNUPGHOME="$tmp_gnupg" gpg --fingerprint releases@wp-cli.org
GNUPGHOME="$tmp_gnupg" gpg --verify wp-cli.phar.asc wp-cli.phar
rm -rf "$tmp_gnupg"

Relevant output includes the WP-CLI release key fingerprint and a valid signature:

pub   rsa2048 2018-05-31 [SC]
      63AF 7AA1 5067 C056 16FD  DD88 A3A2 E8F2 26F0 BC06
uid           [ unknown] WP-CLI Releases <releases@wp-cli.org>

gpg: Good signature from "WP-CLI Releases <releases@wp-cli.org>" [unknown]
Primary key fingerprint: 63AF 7AA1 5067 C056 16FD  DD88 A3A2 E8F2 26F0 BC06

GnuPG can also warn that the key is not certified with a trusted signature. That warning is normal for a key you imported only for this check; the important parts are the fingerprint and the Good signature line.

Install the WP-CLI Command

Test the PHAR before copying it into a system path:

php wp-cli.phar --version
WP-CLI 2.12.0

Install it as /usr/local/bin/wp. The install -m 0755 command copies the file and sets it readable and executable by normal users in one step, which avoids a separate chmod command.

sudo install -m 0755 wp-cli.phar /usr/local/bin/wp

Confirm that your shell finds the installed command:

command -v wp
wp --version
/usr/local/bin/wp
WP-CLI 2.12.0

If WP-CLI has published a newer stable release, your version number will be higher.

After installation succeeds, remove the downloaded copies from the current directory. This does not remove the installed /usr/local/bin/wp command.

rm -f wp-cli.phar wp-cli.phar.asc wp-cli.pgp

Use WP-CLI on Ubuntu

WP-CLI can inspect itself without a WordPress site, but most WordPress commands need either the current directory to contain WordPress files or a --path argument pointing at them.

Check WP-CLI Runtime Details

Use wp cli info when you need to confirm which PHP binary, configuration file, and WP-CLI version the command is using:

wp cli info

Relevant output includes:

PHP binary: /usr/bin/php8.5
PHP version: 8.5.4
php.ini used: /etc/php/8.5/cli/php.ini
WP-CLI version: 2.12.0

The PHP version and php.ini path change by Ubuntu release and by any custom PHP setup you have installed.

Create a Safe WP-CLI Demo Directory

A demo directory lets you confirm the core download and path handling without touching a production site or database:

mkdir -p ~/wp-cli-demo
wp core download --path=~/wp-cli-demo --skip-content
wp core version --path=~/wp-cli-demo

The download command names the current WordPress release and verifies its archive. The stable success line is:

Success: WordPress downloaded.

The final wp core version line prints the downloaded WordPress version number, which changes as WordPress publishes new releases.

Remove the demo files when you no longer need them:

The next command permanently deletes the demo directory created in this section. Check the path before running it if you reused the directory for anything else.

rm -rf ~/wp-cli-demo

Run WP-CLI on an Existing Ubuntu WordPress Site

Ubuntu web stacks often place WordPress under /var/www/ and run PHP through the www-data service account. Check the site owner before running maintenance commands so WP-CLI does not create root-owned files in the document root.

stat -c '%U:%G' /var/www/example.com/wp-config.php

If the owner is www-data, run site commands as that account and point WP-CLI at the WordPress directory:

sudo -u www-data -H wp --path=/var/www/example.com core version
sudo -u www-data -H wp --path=/var/www/example.com plugin list
sudo -u www-data -H wp --path=/var/www/example.com theme list

Replace /var/www/example.com with your real WordPress path. If stat shows another owner, replace www-data with that user instead.

For a complete Ubuntu WordPress stack before you start using WP-CLI, use the same-distro walkthrough to install WordPress with Nginx, MariaDB, and PHP on Ubuntu. If your site only needs the PHP runtime adjusted, the broader PHP on Ubuntu guide covers packaged PHP branches and extensions.

Use Common WP-CLI Maintenance Commands

Use the same Ubuntu web-root pattern for routine maintenance. The read-only checks are safe during normal administration, while update commands should wait until you have a current backup and a maintenance window.

# Read-only checks
sudo -u www-data -H wp --path=/var/www/example.com option get siteurl
sudo -u www-data -H wp --path=/var/www/example.com core check-update
sudo -u www-data -H wp --path=/var/www/example.com plugin status

# State-changing maintenance
sudo -u www-data -H wp --path=/var/www/example.com plugin update --all
sudo -u www-data -H wp --path=/var/www/example.com cache flush

WP-CLI’s official quick start has more examples for downloading core, activating plugins, and running day-to-day WordPress tasks from the terminal.

Manage WP-CLI Packages and Remote Commands on Ubuntu

WP-CLI packages extend WP-CLI itself with extra subcommands. They are different from WordPress plugins, which you manage with commands such as wp plugin install inside a WordPress site.

List and Install Optional WP-CLI Packages

List installed WP-CLI packages first. A fresh account normally has none:

wp package list
name  authors  version  update  update_version

The official WP-CLI package guide supports package names, Git URLs, local directories, and ZIP files. Package installation depends on Composer and GitHub access for the shell user running WP-CLI, but the command shape for a named package looks like this:

wp package install wp-cli/server-command

Packages install under ~/.wp-cli/packages/ by default, so they belong to the shell user running the command. If Composer reports a GitHub authentication warning while installing a package, treat it as a Composer or GitHub access issue, not a broken WP-CLI binary.

Update installed WP-CLI packages after reviewing wp package list. To remove a package, replace the example name with the package shown in your own package list:

wp package update
wp package uninstall wp-cli/server-command

Run WP-CLI Commands Remotely over SSH

WP-CLI can run against a remote WordPress installation with the global --ssh parameter documented in the official remote commands guide. SSH authentication must already work, and if the target is an Ubuntu server that still needs a listener, finish the Ubuntu SSH setup first. The remote server must also be able to run WP-CLI.

wp --ssh=deploy@example.com:/var/www/example.com core version
wp --ssh=deploy@example.com:/var/www/example.com plugin list

Use remote commands when your workstation has WP-CLI installed but the WordPress files live on another Ubuntu server. If the remote host cannot find wp, install WP-CLI on that server too or make the remote non-interactive shell expose the path to the wp command.

Update or Remove WP-CLI on Ubuntu

The PHAR install places WP-CLI in /usr/local/bin, so the file is owned by root and updates need elevated privileges. WP-CLI handles PHAR updates through its own cli update command rather than through APT.

Update WP-CLI on Ubuntu

Check for a newer stable PHAR and accept the update automatically:

sudo wp cli update --yes

When the installed build is already current, WP-CLI reports:

Success: WP-CLI is at the latest version.

Remove WP-CLI from Ubuntu

Remove the system-wide launcher file:

sudo rm -f /usr/local/bin/wp

Confirm that the command is no longer on your PATH:

command -v wp || echo "wp command removed"
wp command removed

The next cleanup command deletes WP-CLI cache files and optional WP-CLI packages for your current user. Skip it if you plan to reinstall WP-CLI or keep package extensions.

rm -rf ~/.wp-cli/cache ~/.wp-cli/packages

Leave PHP, ZIP, curl, certificate, and GnuPG packages installed unless you know no WordPress site, PHP script, or other maintenance workflow still needs them.

Troubleshoot WP-CLI on Ubuntu

Most WP-CLI problems on Ubuntu come from a missing PHP CLI package, an incorrect WordPress path, file ownership, or optional package-manager network access.

Fix php: command not found

If PHP is missing, the PHAR cannot run:

bash: php: command not found

Install the Ubuntu PHP CLI package and try the WP-CLI version check again:

sudo apt update
sudo apt install php-cli php-zip
wp --version

Fix Extracting a zip file requires ZipArchive

If wp core download or a package-related command needs ZIP support, PHP CLI must be able to load the ZipArchive extension:

Error: Extracting a zip file requires ZipArchive.

Install Ubuntu’s default PHP ZIP module, then rerun the WP-CLI command that failed:

sudo apt update
sudo apt install php-zip
wp core download --path=~/wp-cli-demo --skip-content

A successful retry ends with:

Success: WordPress downloaded.

If wp cli info shows a custom PHP branch instead of Ubuntu’s default branch, install the matching versioned ZIP module for that PHP runtime.

Fix wp: command not found

If the shell cannot find wp, check whether the file exists in the system path used for the PHAR install:

ls -l /usr/local/bin/wp
echo "$PATH" | tr ':' '\n' | grep -Fx /usr/local/bin

If the file is missing, reinstall the PHAR with sudo install -m 0755 wp-cli.phar /usr/local/bin/wp. If the file exists but /usr/local/bin is missing from PATH, open a new login shell or fix the shell profile that removed the standard path entry.

Fix This does not seem to be a WordPress installation

WP-CLI prints this error when the current directory is not a WordPress installation and no --path argument was supplied:

Error: This does not seem to be a WordPress installation.
Pass --path=`path/to/wordpress` or run `wp core download`.

Move into the WordPress directory or pass the path explicitly:

cd /var/www/example.com
sudo -u www-data -H wp core version

# Or stay anywhere and use --path
sudo -u www-data -H wp --path=/var/www/example.com core version

Avoid Root-Owned WordPress Files

Using sudo wp for normal site commands can create files owned by root inside uploads, cache, plugin, or upgrade directories. Use sudo -u www-data -H for sites owned by www-data, or replace www-data with the owner shown by stat.

stat -c '%U:%G' /var/www/example.com/wp-config.php
sudo -u www-data -H wp --path=/var/www/example.com plugin list

Fix Failed to get latest version During WP-CLI Updates

If an update check cannot reach the upstream release endpoint, WP-CLI can fail before it downloads anything:

Error: Failed to get latest version (HTTP code 403).

Wait and retry first, especially on shared networks, CI runners, or reused servers that may have hit an upstream rate limit. If the error persists, repeat the signed PHAR download and sudo install -m 0755 wp-cli.phar /usr/local/bin/wp flow from the install section instead of forcing an unauthenticated update check.

Handle WP-CLI Package GitHub Authentication Warnings

Optional WP-CLI package installs use Composer and may contact GitHub. If GitHub rejects anonymous access, WP-CLI can fail with:

Warning: Could not authenticate against github.com
Error: Package installation failed.

Retry later, configure Composer or GitHub authentication for that shell user, or skip the optional WP-CLI package if you only need the core wp command. Normal WordPress plugin commands such as wp plugin list and wp plugin update do not require the WP-CLI package manager.

Conclusion

WP-CLI is available on Ubuntu as a signed, system-wide wp command, with updates handled by wp cli update and site commands scoped to the right WordPress path or web-server user. For the next layer, pair it with Install Composer on Ubuntu for PHP projects or Secure Nginx with Let’s Encrypt on Ubuntu before public launch.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: