1

Summarizing my problem

  • Details about my goal:
    I want to install an older(stable) version of Rails; specifically 5.2.5.

  • Describing the expected and actual results:
    I expect my Mac running Big Sur v11.3.1 (apple m1) to install Rails successfully.

The actual result is (presumably) a permission/ownership based error:

$ gem install rails -v 5.2.5
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.9/CHANGELOG.md

Obviously I see it's something to do with concurrent-ruby-1.1.9...though I continue to get this error with other gems throughout my efforts to install rails on this new-ish computer.

Describing what I've tried:

Both solutions here - no help

i've read this question - no help

I've read this question, but it's old

I've begun to explore my PATH:

/Users/ayylmao/.rbenv/shims:/Users/ayylmao/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

and I've uninstalled previous installations of Rails (and railties), as well as removed rbenv and re-installed (via the usual for me, Homebrew)

I've run brew doctor, i've updated gems with gem update, i've gotten rid of seemingly superfluous gems with for i in gem list --no-versions; do gem uninstall -aIx $i; done.

Obviously, i'm at my wits end here...

My best guess

looking at my $PATH it seems super "sus"...looks like there's some redundancy...but I'm not certain how to troubleshoot it or if that's the correct place to be looking.

I've dropped most details about my system and environment throughout my question, but here's an agregate:

  • MacOS BigSur 11.3.1 (perhaps something to do with Apple's SIP?) smh
  • zsh
  • homebrew
  • rbenv
  • ruby 2.7.2

stating my question without any ambiguity

How do I troubleshoot this error "Permission denied @ rb_sysopen" via closer inspection of my $PATH? And is that the most likely culprit?

What steps would I need to take to go completely "nuclear"?

PS - full disclosure...yes I have used sudo in some instance of installing rails...though i've quickly uninstalled those versions shortly after installation. I apologize for the irresponsibility. I was not prepared for the Apple SIP and panicked months ago....Also, ZSH was a change for me as well.

J.R. Bob Dobbs
  • 237
  • 3
  • 10

1 Answers1

2

It seems like your ruby installation through rbenv was made via sudo, which will create gem structure with root privileges.

So, when you perform a gem install rails from a regular user, you won't have the privileges to write into gems directory, raising the permission denied error.

You can confirm the permission by running:

ls -la /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/

Try to reinstall your ruby with you own user (without sudo) and the installation of rails or other gems will sould be fine.

manuwell
  • 402
  • 2
  • 8
  • So, I ran `ls -la /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/` and can confirm some gems are owned by `root` and some are owned by `ayylmao`. Should I see a `ruby` or `rails`? @wjsantos ? – J.R. Bob Dobbs Aug 07 '21 at 15:50
  • 2
    so, if you have both, I recommend you change the `root` owner of all your gems to your user `ayylmao`. You can run: `sudo chown -R ayylmao:ayylmao /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/`. After that, try to install rails again – manuwell Aug 07 '21 at 15:58
  • This is the selected answer; and can be used for most permission errors; I had to continue to `sudo chown -R username /Users/username/every/time/it/got/stuck` and this fixed; Cheers to @wjsantos – J.R. Bob Dobbs Aug 07 '21 at 16:45
  • Many issues are caused by installing gems with `sudo`, and it should be avoided. – B Seven Aug 08 '21 at 18:06