MacOS Installation Gem::FilePermissionError

When installing Discourse (for development) on my Mac I get this error:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

How can I resolve this?

Did you run through the script install of Discourse here?

Are you running macOS Catalina? If that’s the case, it sounds like you’re running into Discourse trying to use the system version of ruby. You’ll want to use something like rbenv to set your ruby version to avoid this.

1 Like

I am running MacOS Catalina. And I did run that script but it failed half way through because it was installed I think.

Can you paste the output of which rbenv?

And do you have a custom .bashrc or .zshrc?

1 Like


Not really sure. I don’t think so but maybe.

Can you cd into your discourse directory and share the output of which ruby?

1 Like

Oops, didn’t notice. I did it and got /usr/bin/ruby

Okay, so you’re using the system ruby for Discourse which is why you’re getting that issue.

Check the PATH variable by typing in echo $PATH. You should see /Users/<your username>/.rbenv/bin and /Users/<your username>/.rbenv/shims listed in there.

If not, add them in your shell’s configuration file .bashrc or .zshrc. For ZSH you can add it like this: export PATH=/path/number/1:/path/number/2:$PATH

If you do see them, check to see what order they’re in. If they are later in the chain, they’re probably not getting loaded before the system ruby meaning the system ruby is being used for Discourse. You can use the same approach above for moving the paths further up the chain.


I thought @david added a Ruby version check to our dev environment stuff? :thinking:

I believe that was for the theme cli.


Is there some way to add an equivalent check here?

I think we already check in Discourse for ruby version compatibility — the issue here is our Discourse bundle can’t write gems for the system level version of ruby bundled with macOS. I could be wrong on the specific details but I think it has to do with a change Apple made with macOS Catalina. I ran into this same issue myself and it took a good deal of troubleshooting to figure out.

1 Like
  1. I encountered the same error as the OP.

  2. Read this:

  1. Thought that it’s not actually a file permission error, rather the installer was looking at the wrong place.

  2. I knew that restarting the terminal would reload my .zshrc file, so I closed and opened the terminal.

  3. I run the installation script again and I didn’t encounter this error anymore.

Could this issue be resolved with a terminal refresh strategically placed during the install process? :thinking: