Installing WP-CLI on Ubuntu or Debian moves routine WordPress administration into repeatable shell commands, which is useful for plugin maintenance, URL changes, cache flushes, and scripted operations. A working wp command also makes later maintenance easier to audit because the exact action can be rerun from shell history instead of repeated by hand in the dashboard.

The wp command is a PHP-based Phar application that loads the current WordPress install from the working directory, reads wp-config.php, and then runs the requested subcommand against that site. The official WP-CLI handbook still recommends the Phar build as the main installation method, so the same flow works cleanly on both Ubuntu and Debian without depending on distro-specific packaging.

The steps below install the current distro packages for PHP CLI, curl, and less, then place the official WP-CLI Phar on the normal command path as wp. Current Ubuntu and Debian repositories do not expose a direct wp-cli package, so the upstream Phar is the clearest supported path; a successful wp --info check confirms the CLI is installed, while database-focused subcommands can still depend on extra tools such as mysqldump.

Steps to install WP-CLI on Ubuntu or Debian:

  1. Update the package index.
    $ sudo apt-get update
    Reading package lists... Done
  2. Install the command-line prerequisites for WP-CLI.
    $ sudo apt-get install --yes ca-certificates curl php-cli less
    Reading package lists... Done
    Building dependency tree... Done
    The following NEW packages will be installed:
      ca-certificates curl less php-cli
    ##### snipped #####

    The verified Ubuntu 24.04 run installed php8.3-cli, while current Debian 12 uses the same php-cli package name with the distro's PHP CLI version.

  3. Download the official WP-CLI Phar build.
    $ curl -fsSLO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

    The official WP-CLI handbook treats the Phar build as the recommended install path on Linux, even though upstream also publishes optional .deb artifacts.

  4. Make the downloaded file executable.
    $ chmod +x wp-cli.phar
  5. Move the executable into a directory on the default command path.
    $ sudo mv wp-cli.phar /usr/local/bin/wp
  6. Confirm that the wp command is available system-wide.
    $ wp --info
    OS:	Linux 6.12.76-linuxkit #1 SMP Fri Mar  6 10:10:19 UTC 2026 aarch64
    PHP binary:	/usr/bin/php8.3
    PHP version:	8.3.6
    php.ini used:	/etc/php/8.3/cli/php.ini
    WP_CLI phar path:	phar:///usr/local/bin/wp
    WP-CLI version:	2.12.0

    If the shell still reports wp: command not found, confirm that /usr/local/bin is in the active PATH and that the file was moved as wp rather than left as wp-cli.phar.

  7. Change into the target WordPress document root before running site-specific commands.
    $ cd /var/www/example.com/public_html

    Use the directory that contains wp-config.php for the site that the command should manage.

  8. Run a read-only WP-CLI command against the site to confirm the CLI can load WordPress correctly.
    $ wp core version
    6.9.4

    If the command is being tested from a root shell inside a disposable container, append --allow-root for that one check; on a normal host, prefer the account that already owns the site files.