Install WP‑CLI on Linux in 5 minutes
If you’ve finally got SSH access to your box and you’re tired of typing long URLs into your browser just to clear caches, this guide will get WP‑CLI up and running fast. You’ll end up with a single wp command that works from any directory, and I’ll point out the little traps that usually bite newcomers.
Grab the PHAR file where it belongs
cd /opt curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Downloading to /opt keeps system‑wide binaries tidy and makes sure you have write permission without resorting to sudo. If the download fails, curl will complain loudly – don’t ignore that.
Verify the download actually worked
php wp-cli.phar --info
Running --info does two things: it checks that PHP can parse the PHAR and it shows you which PHP version is being used. I’ve seen this step save me a lot of head‑scratching when the server’s default php points at an old 5.2 binary.
Make it executable and move it to your PATH
chmod +x wp-cli.phar # marks the file as runnable
sudo mv wp-cli.phar /usr/local/bin/wp # puts a short name in a directory that’s already on $PATH
chmod +x is required because a PHAR isn’t automatically executable. Moving it to /usr/local/bin means you can call wp from anywhere without typing the full path each time.
Test the installation from your WordPress root
cd /var/www/html/your‑site wp core version
If the command prints something like “WordPress 6.x.x”, you’re good to go. The first time I ran this as root, WP‑CLI threw an error about running under the root user; adding --allow-root fixes it, but a better practice is to create a regular SSH user for WordPress tasks.
(Optional) Tweak your shell for tab completion
wp cli completions bash > /etc/bash_completion.d/wp-cli
This isn’t required, but it turns wp <TAB> into a handy shortcut for sub‑commands and arguments – a small time‑saver that feels like cheating.
That’s the whole process. You now have a lean command line interface to update plugins, flush caches, or even scaffold new themes without touching the admin UI.