Guide · Open source
How to use RuboCop: install, run and auto-fix Ruby style
Updated · written with AI from the project's own documentation and checked against our catalogue data
RuboCop is a Ruby static code analyzer, often called a linter, and a code formatter. It checks your Ruby code against many guidelines from the community Ruby Style Guide and can automatically fix many of the problems it finds. This guide shows you how to install it, run it on a project, and where to find the options that control its behavior.
Quick start
- 1Check your Ruby version. Confirm you run MRI 2.7+ or JRuby 9.4+, the runtimes the README lists as officially supported.
- 2Install the gem. Run gem install rubocop in your terminal.
- 3Open your project. Change into the folder of the Ruby project you want to check.
- 4Run RuboCop. Type rubocop in the project folder to analyze the code and see reported issues.
- 5Auto-fix what it can. Let RuboCop automatically fix the many problems it is able to correct, then review the changes.
- 6Tune the configuration. Adjust options to match your team's style, using the default configuration reference as a guide.
What RuboCop does
RuboCop is a static code analyzer for Ruby. Out of the box it enforces many of the guidelines in the community Ruby Style Guide. Besides reporting problems, it can automatically fix many of them for you.
Most aspects of its behavior can be tweaked through configuration options, so you can adjust it to match your team's preferences.
Check the prerequisites
RuboCop runs on Ruby and is installed with RubyGems, using the gem command. The README lists MRI 2.7+ or JRuby 9.4+ as the officially supported runtime Ruby implementations. It targets Ruby 2.0+ for code analysis.
- Ruby (MRI 2.7+ or JRuby 9.4+)
- RubyGems (the gem command)
Install RuboCop with gem install
The standard way to install RuboCop is to install the gem from your terminal.
gem install rubocopInstall RuboCop with Bundler
If you prefer Bundler, add RuboCop to your Gemfile. Set the require option to false, because RuboCop is a standalone tool and should not be loaded by your application.
To avoid unwanted updates, you can pin a conservative version range in your Gemfile. RuboCop is stable between minor versions in terms of API and cop configuration.
gem 'rubocop', require: falseRun RuboCop on your project
Change into a Ruby project's folder and type rubocop. It analyzes the project and reports the issues it finds.
You can also use RuboCop's built-in LSP server to get the same checks inside your editor.
cd my/cool/ruby/project
rubocopConfigure RuboCop to fit your team
Because most of its behavior is set through configuration options, you can change which checks apply and how strict they are. The default configuration file lists all the available options and their defaults, and the official docs explain the versioning policy and compatibility in more detail.
- Read the default configuration reference in config/default.yml in the rubocop repository.
- Read the official docs at docs.rubocop.org for more details.
What people use it for
- Keeping style consistent across a Ruby project with many contributors
- Running an automated style check during development
- Following the community Ruby Style Guide in an open-source Ruby library
- Cleaning up or upgrading an existing Ruby codebase
Frequently asked questions
Is RuboCop free to use?
RuboCop is free software released under the MIT licence. The project also accepts financial support through several funding channels, but the tool itself is free to use.
How do I install RuboCop?
Run gem install rubocop in your terminal. If you use Bundler, add gem 'rubocop', require: false to your Gemfile instead.
What are the requirements for RuboCop?
You need Ruby and RubyGems. The README lists MRI 2.7+ or JRuby 9.4+ as the officially supported runtimes.
Can RuboCop fix my code automatically?
Yes. Besides reporting problems, RuboCop can automatically fix many of them.
Can I use RuboCop on non-Ruby projects?
No. RuboCop only analyzes Ruby code, so it is not suitable for other languages.
How does RuboCop compare to ESLint, Standard or Reek?
ESLint is a comparable tool for JavaScript, while Standard and Reek are other Ruby-focused tools mentioned alongside RuboCop. This source does not compare their features in detail, so check each project's documentation before choosing.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
RuboCop suits Ruby developers and teams who want consistent, automatically checked style that follows the community Ruby Style Guide, and who are comfortable maintaining a configuration file. It is a poor fit for non-Ruby projects or for anyone who does not want to manage configuration options, in which case a tool with fewer settings may be a better choice.
Install options & downloads