Error when installing Rubocop globally on Macos using rbenv and homebrew

To use the Rubocop gem with VSCode to assist with code linting, it’s sometimes desirable to have Rubocop installed at the system level. I recently ran into a permissions problem when using the homebrew version of Ruby to install Rubocop, and this was the solution:

➜ gem install rubocop
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
➜ rbenv install -l
➜ rbenv install 3.0.2
➜ rbenv global 3.0.2
➜ ruby --version

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
➜ gem install rubocop

(long pause)

Done installing documentation for unicode-display_width, ruby-progressbar, ast, parser, rubocop-ast, regexp_parser, rainbow, parallel, rubocop after 24 seconds
9 gems installed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s