Install Redocly CLI

There are two ways to install Redocly CLI: global and runtime.

Global installation

npm

Tip

This is the recommended method. Ensure you have the latest version of npm before you begin.

CommandOutput
Copy
Copied
npm i -g @redocly/cli@latest
Copy
Copied
npm i -g @redocly/cli@latest
added 1 package, removed 1 package, changed 87 packages, and audited 89 packages in 4s
found 0 vulnerabilities

Yarn

CommandOutput
Copy
Copied
yarn global add @redocly/cli
Copy
Copied
yarn global add @redocly/cli
yarn global v1.22.11
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Installed "@redocly/cli@1.0.0-beta.96" with binaries:
      - openapi
      - redocly
✨  Done in 6.90s.

Verify the installation

Running redocly --version will confirm that the installation was successful:

Copy
Copied
redocly --version
1.0.0-beta.96

Runtime installation

npx

info

npx is npm's package runner. It will install and run a command at the same time without installing globally.

CommandExample with lint commandOutput (lint failed)Output (lint succeeded)
Copy
Copied
npx @redocly/cli <command> [options]
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
No configurations were defined in extends -- using built in recommended configuration by default.

validating petstore.yaml...
[1] petstore.yaml:6:5 at #/info/license

License object should contain `url` field.

4 |   title: Swagger Petstore
5 |   license:
6 |     name: MIT
7 | host: petstore.swagger.io
8 | basePath: /v1

Warning was generated by the info-license-url rule.


petstore.yaml: validated in 70ms

Woohoo! Your OpenAPI definition is valid. 🎉
You have 1 warning.
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
No configurations were defined in extends -- using built in recommended configuration by default.

validating petstore.yaml...
petstore.yaml: validated in 43ms

Woohoo! Your OpenAPI definition is valid. 🎉

Docker

To give a Docker container access to your OpenAPI definition files, you need to mount the containing directory as a volume. Assuming the definition is rooted in the current working directory, the command to use is:

Example with lint commandOutput (lint succeeded)
Copy
Copied
docker run --rm -v $PWD:/spec redocly/cli lint petstore.yaml
Copy
Copied
Unable to find image 'redocly/cli:latest' locally
latest: Pulling from redocly/cli
6875df1f5354: Pull complete 
8bbbdaf00b73: Pull complete 
07345efefd1e: Pull complete 
14905c1e5030: Pull complete 
7fda3ee50334: Pull complete 
aaed5f965b97: Pull complete 
0fa91aa56ecc: Pull complete 
36fba6be8742: Pull complete 
45b4272e5445: Pull complete 
aeb22d467cb4: Pull complete 
0f16197cc5ee: Pull complete 
e3616581d311: Pull complete 
f942cf7214e0: Pull complete 
6d2dbb2f00b2: Pull complete 
88e9dfd6b46f: Pull complete 
38ffc139afee: Pull complete 
Digest: sha256:f7cc187c5d470c5c453a2fe70445ff28a997cf7fd138cbdff89fc6b7a077778f
Status: Downloaded newer image for redocly/cli:latest
No configurations were provided -- using built in recommended configuration by default.

validating petstore.yaml...
petstore.yaml: validated in 51ms

Woohoo! Your OpenAPI definition is valid. 🎉

Set up tab completion (optional)

After a successful install, you can set up tab completion for the terminal if you wish. Generate the completion script using the following command:

CommandOutput
Copy
Copied
redocly completion
Copy
Copied
###-begin-openapi-completions-###
#
# yargs command completion script
#
# Installation: /Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi completion >> ~/.bashrc
#    or /Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi completion >> ~/.bash_profile on OSX.
#
_openapi_yargs_completions()
{
    local cur_word args type_list

    cur_word="${COMP_WORDS[COMP_CWORD]}"
    args=("${COMP_WORDS[@]}")

    # ask yargs to generate completions.
    type_list=$(/Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi --get-yargs-completions "${args[@]}")

    COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) )

    # if no match was found, fall back to filename completion
    if [ ${#COMPREPLY[@]} -eq 0 ]; then
      COMPREPLY=()
    fi

    return 0
}
complete -o default -F _openapi_yargs_completions openapi
###-end-openapi-completions-###

The command output contains installation instructions. For example, to install the completion script in bash, use:

Copy
Copied
redocly completion >> ~/.bashrc

The approach is similar for other shells. After the installation, restart your terminal for the changes to take effect.

Next steps