How to install WP-CLI with Composer without sudo

There are a number of ways to install WP-CLI. However you might run into problems if you want to avoid using sudo. The default installation symlinks the wp command line interface into /usr/local/bin which requires sudo. Since Composer already allows us to manage PHP libraries easily, it makes sense to reuse it with wp-cli as well.

To proceed, first ensure that Composer’s vendor bin is in your PATH. If it isn’t add it to your bashrc.

export PATH=~/.composer/vendor/bin:$PATH

Next install WP_CLI using the Composer require command. Using global allows the wp command line interface to be available across all projects.

$ composer global require wp-cli/wp-cli:v0.14.0

To track the bleeding-edge version on GitHub, use dev-master as the version,

$ composer global require wp-cli/wp-cli:dev-master

That’s it. After installation you will have an additional wp command available to you. You can confirm that it’s using the correct version,

$ which wp
$ wp --version
WP-CLI 0.14.0

Here the wp command is coming from the local Composer vendor bin that we added to the bash PATH earlier.

  • Fahad M Rafiq

    Managing multiple WordPress websites is a hectic job, as you have to logging to each site and setup/install plugins and settings for each site independently.

    Luckily for those well versed to work in command line, they can use WP-CLI to manage multiple WordPress sites with just a few commands. WP-CLI comes with built-in commands specific just to manage WordPress websites.

    Through WP-CLI you can install, manage plugins and themes. Control settings such as cron-job, comments etc.

    Learn a few basic commands here: