# Install Redocly CLI There are two ways to install Redocly CLI: global and runtime. ## Global installation ### npm :::success Tip This is the recommended method. Ensure you have the latest version of npm before you begin. ::: ```shell Command npm i -g @redocly/cli@latest ``` ```shell Output 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 ```shell Command yarn global add @redocly/cli ``` ```shell Output 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: ```shell 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. ::: ```shell Command npx @redocly/cli [options] ``` ```shell Example with lint command npx @redocly/cli@latest lint petstore.yaml ``` ```shell Output (lint failed) 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:3:3 at #/info Info object should contain `description` field. 1 | swagger: "2.0" 2 | info: 3 | version: 1.0.0 4 | title: Swagger Petstore 5 | license: 6 | name: MIT 7 | host: petstore.swagger.io 8 | basePath: /v1 Warning was generated by the info-description rule. [2] 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 2 warnings. ``` ```shell Output (lint succeeded) 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: ```shell Example with lint command docker run --rm -v $PWD:/spec redocly/openapi-cli lint petstore.yaml ``` ```shell Output (lint succeeded) Unable to find image 'redocly/openapi-cli:latest' locally latest: Pulling from redocly/openapi-cli 540db60ca938: Pull complete fe289da0f830: Pull complete c5a1e48e74e5: Pull complete 63ccc02b1289: Pull complete 4b42ba54a874: Pull complete 3f76218e8e91: Pull complete Digest: sha256:fa95c9a8b9e282b21779e8ffa86ed28b87f9d97517e46d96af7a6676d47b0430 Status: Downloaded newer image for redocly/openapi-cli:latest No configurations were defined in extends -- 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: ```shell Command redocly completion ``` ```shell Output ###-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: ```shell Command openapi completion >> ~/.bashrc ``` The approach is similar for other shells. After the installation, restart your terminal for the changes to take effect. ## Next steps - Check the full list of [Redocly CLI commands](./commands/index.md) available to you - Learn how to fine-tune your Redocly CLI tool using a [configuration file](./configuration/index.mdx) - Learn more about [custom plugins and rules](./resources/custom-rules.md)