• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Install Multiple WordPress Plugins with WP CLI
Command line output from running command to install multiple plugins.

Install Multiple WordPress Plugins with WP CLI

Last updated on January 24, 2018 by Sal Ferrarello

At a recent WordPress meetup we were discussing WP CLI and the comment came up, “When setting up a site, it would be nice to install a bunch of plugins with a single command.”

Fortunately a WordPress meetup is a great place to bounce ideas off of smart people and find a solution.

Solution 1: Using a Text File

The first solution we crafted was to use a text file with each plugin slug on a separate line, like the following.

plugin-slugs.txt

stop-emails
modify-comment-parent
simple-google-analytics-tracking

Then we could run the following, which would install and activate each plugin.

wp plugin install --activate $(<plugin-slugs.txt)

Solution 2: A Long Command

While using a text file for the slugs is a great solution, we realized it would be even nicer if we didn’t need a separate file. Instead we wanted to provide a single line, even if it is a long line, to install multiple plugins.

The following will install and activate the listed plugins.

wp plugin install --activate stop-emails modify-comment-parent simple-google-analytics-tracking

Edited Thanks to Tim’s comment, I’ve removed the extraneous echo that appeared in an earlier version of this command.

xargs throws root warning

Interestingly, I would expect the following to work as well

echo stop-emails modify-comment-parent simple-google-analytics-tracking | xargs wp plugin install --activate

however, it does not. Instead it displays an error.

Error: YIKES! It looks like you’re running this as root. You probably meant to run this as the user that your WordPress install exists under.

We are able to avoid this error and run the command but we have to use the --allow-root flag, which seems like poor form.

Do not use this command, instead please use Solution 2: A Long Command

echo stop-emails modify-comment-parent simple-google-analytics-tracking | xargs wp plugin install --activate --allow-root
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Dev Tips, Programming, Solution Tagged With: command line, WordPress, wp-cli

Reader Interactions

Comments

  1. Tim says

    January 24, 2018 at 12:21 pm

    Hey Sal, this is a super time saver that I use all the time. I always run the command without ‘echo’, like so:

    wp plugin install stop-emails modify-comment-parent simple-google-analytics-tracking –activate.

    Is there a benefit to running the command with $(echo)?

    Reply
    • Sal Ferrarello says

      January 24, 2018 at 12:36 pm

      Wow that is a great point Tim – thank you. I’ve updated this post from the original

      wp plugin install --activate $(echo stop-emails modify-comment-parent simple-google-analytics-tracking)

      to your much improved

      wp plugin install --activate stop-emails modify-comment-parent simple-google-analytics-tracking

      Thanks.

      Reply
  2. Matt Ryan says

    January 25, 2018 at 7:20 am

    Love the updated long command solution. Copy & paste reduces the keystrokes completely. Thanks Sal & Tim.

    Reply
  3. Matt Ryan says

    January 30, 2018 at 10:26 am

    Just had to follow up on this with today’s real world use case.

    – ssh’ed into local by flywheel site in one command window
    – ssh’ed into client website on GoDaddy in another command window
    – arrange side by side command windows
    – “wp plugin list” in each command window to see what is installed locally and on staging
    – entered the “long command” and watched 15 plug’s get installed and activated while I sipped my coffee

    #lifeisgood

    Reply
    • Sal Ferrarello says

      January 31, 2018 at 9:20 am

      Rock on! Nice work.

      Reply
  4. Markus Huria says

    November 16, 2018 at 9:11 pm

    Hey Sal,

    I absolutely love this! It took me too long to find this article, thanks heaps!

    Is there a way for us to install plugins using WP CLI that aren’t listed in the WordPress Repository?

    Reply
    • Sal Ferrarello says

      November 18, 2018 at 8:32 pm

      Hi Markus,

      I’m glad this post was helpful.

      Is there a way for us to install plugins using WP CLI that aren’t listed in the WordPress Repository?

      Yes, you can install a plugin from a zip file using WP CLI.

      Reply
  5. Florian says

    October 25, 2019 at 9:08 am

    Is it possible to install multiple plugins, each with a specified version in one command?

    Reply
    • Sal Ferrarello says

      October 25, 2019 at 11:13 pm

      Not that I’m aware of. Since version is specified with `–version=`, I don’t see a way to provide more than one value.

      If you figure something else out, I’d love to hear about it.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in