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?
Thanks.

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

/usr/local/bin/rbenv

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.

3 Likes

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

I believe that was for the theme cli.

2 Likes

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