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

4 thoughts on “Error when installing Rubocop globally on Macos using rbenv and homebrew

  1. I’ve ran into this issue myself – however – not trying to be difficult, but wouldn’t a simple “sudo gem install rubocop” have worked better?

    I’ve just done that and it installed it, just fine.


      1. I suppose that’s right, but in the case of Ruby as an interpreter – it’s kinda the case of “6 of one – half a dozen of the other” – it is entirely conceivable that even if you install a parallel version of ruby, you may still end up inadvertently running stuff as root with that version of Ruby, and suddenly, the risk is the same.


      2. I’m not across the technical details as to why, but every advice I’ve read is to avoid running Ruby as root in these situations . I use rbenv to manage the different Ruby versions on my devbox and it works ok.


Leave a Reply

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

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

Facebook photo

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

Connecting to %s