Title: Install PHPCS globally
Author: WordPress VIP Documentation
Published: September 4, 2023
Last modified: December 29, 2025

---

 1. [PHPCS for WordPress VIP](https://docs.wpvip.com/php_codesniffer/)
 2. Install PHPCS globally

#  Install PHPCS globally

Installing PHPCS globally makes PHPCS available for use from anywhere on a local
machine. Following these instructions will install:

 * The latest compatible version of PHPCS
 * The latest release of [VIP-Coding-Standards (VIPCS)](https://github.com/Automattic/VIP-Coding-Standards/releases)
 * A compatible version of the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)(
   WordPressCS)
 * Compatible versions of other standards packages, like VariableAnalysis, PHPCSUtils
   and PHPCSExtra

**Note**

PHPCS commands on a local machine running [Windows may require different formatting](https://www.php.net/manual/en/install.windows.commandline.php)
than the command examples shown below.

## Install

 1. Before beginning installation, ensure that Composer itself is up to date:

    ```wp-block-preformatted
    composer self-update && composer global update
    ```

 2. Run the command below in a terminal. This command can be run to update an existing
    global installation. Verbose output in the terminal will indicate what is being
    installed (or updated).

    ```wp-block-preformatted
    composer g require --dev automattic/vipwpcs -W
    ```

 3. The `phpcs` command should now be in the local machine’s PATH.

    ```wp-block-preformatted
    $ ls ~/.composer/vendor/bin
    phpcbf	phpcs
    ```

 4. Check PHPCS to ensure it is up to date.

    ```wp-block-preformatted
    $ phpcs --version
    PHP_CodeSniffer version 3.7.2 (stable) by Squiz (http://www.squiz.net)
    ```

## Troubleshooting

If the `phpcs` command does not work, the Composer bin directory on the local machine
will need to be added to the `PATH` environment variable. On most operating systems,
the `phpcbf` and `phpcs` files are located in the `~/.composer/vendor/bin` directory.

On a local machine running Linux, the file path might be `~/.config/composer/vendor/
bin`. Verify the location of the `phpcbf` and `phpcs` files on the user’s local 
machine, and modify the file path as needed when following the instructions below.

 1. Edit the local machine’s shell profile (e.g., `~/.bash_profile`, `~/.zshrc`, `~/.
    bashrc`) and add the `PATH` environment variable. The syntax (and the actual file
    that the shell loads on startup) will vary depending on the shell being used. For
    example, in `~/.bash_profile`, add the following code to the end of the file:

.bash_profile

    ```lang-shell
    export PATH="$HOME/.composer/vendor/bin:$PATH"
    ```

 2. After adding and saving the `PATH` environment variable to the shell profile, either:
 3.  * Open a new terminal window
     * or source the shell profile in the existing terminal window by running: `source
       ~/.bash_profile`.

 3.  Run the `phpcs` command again.

Last updated: December 29, 2025