Home Linux Commandline Tools How to Install and Use WP-CLI on Linux [Beginners’ Guide]

How to Install and Use WP-CLI on Linux [Beginners’ Guide]

WordPress has created a reputation for itself as one of the world’s most sort-after open-source CMS (Content Management System) software. The growing popularity of WordPress CMS is due to the fact a non-coder can easily download, install, set up, and start running an enterprise-driven CMS platform.

WordPress design consideration of non-coders does not exclude the need for useful developer tools and documents. One such tool is WP-CLI.

WP-CLI tool provides a command-line interface for the WordPress CMS software, which makes it possible to install, manage, and update WordPress CMS software if need be.

Additionally, if you are handling multiple CMS sites, this tool will help with their configuration and the update of the WordPress backend server’s cores and plugins. Also, when trying to troubleshoot and restore an irresponsive WordPress frontend, WP-CLI is the go-to tool.

Installing WP-CLI in Linux

The WP-CLI archive file we are going to download exists as a PHP Archive (.phar) file and we can retrieve this file with the following wget command.

$ wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Next, we need to make it executable and move the file to the /usr/local/bin directory. This directory stores user command binaries that are executable from the terminal environment.

$ chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp 

To make sure we can access the WP-CLI tool from the command line, check its version as follows:

$ wp --info
Check WP CLI Version
Check WP CLI Version

Updating WP-CLI

You can update WP-CLI with the wp cli update command, or by repeating the installation steps as discussed above.

$ sudo wp cli update

WP-CLI Tab Completions

Next, we need to activate WP-CLI bash completion to auto-complete WP-CLI-related commands via the [Tab] key.

$ wget https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash

Add wp-completion.bash content to your .bashrc file.

$ cat wp-completion.bash >> .bashrc
$ source .bashrc

How to Use WP-CLI Commands in Linux

Once the WP-CLI is installed on the system, you can use it to manage your WordPress installation using the following commands. To execute any of the following commands, you must be in your WordPress installation directory.

WP-CLI Manage WordPress Installation

To download WordPress, use the command:

$ wp core download
WP-CLI Download WordPress
WP-CLI Download WordPress

To install WordPress, first, create the wp-config.php file on your WordPress directory and set the database name and database user. Afterward, you can install WordPress with the command:

$ wp core install 

To check if WordPress is installed, run:

$ wp core is-installed

To check for WordPress updates:

$ wp core check-update 

To update WordPress to the latest release:

$ wp core update

To update your database:

$ wp core update-db

Check the WordPress version:

$ wp core version 

WP-CLI Clear WordPress Cache

If you are running multiple WordPress instances with cache enabled, changes are that cached content needs to be cleared when you make changes to your site or pages. Most of the time, the cache gets cleared automatically, but if you might face a situation where you need to clear the cache manually, then run:

$ wp cache flush

WP-CLI Manage WordPress Plugins

Displays a list of installed plugins on the site with activation status, whether or not there’s an update available, etc.

$ wp plugin list

You can also deactivate any plugin using its name as shown.

$ wp plugin deactivate plugin_name

You can deactivate all installed plugins with one single command:

$ wp plugin deactivate --all

You can also update one or more plugins.

$ wp plugin update plugin_name
$ wp plugin update --all

WP CLI Command Help

To preview all WP-CLI commands and their usage, run:

$ wp help
WP-CLI Help Command
WP-CLI Help Command

To get assistance on the usage of a specific WP-CLI command, implement:

$ wp help <command>

For example:

$ wp help db
WP-CLI Command Help
WP-CLI Command Help

The WP-CLI tool gives Linux users the needed flexibility when it comes to managing their WordPress projects/sites from the comfort of the Linux terminal environment.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.