You don't have write permissions for the /usr/bin directory. while installing Cocoapods
Asked Answered
L

2

51

I'm trying to install Cocoapods using the following command on my Mac:

sudo gem install cocoapods

But I'm getting the following error:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

Really doesn't make sense as I'm doing is via sudo as the root user. Any help will be appreciated!

I'm using gem version 2.7.7 (latest as of today).

Locale answered 19/5, 2018 at 7:15 Comment(0)
R
161

Try this, It worked for me

sudo gem install cocoapods -n /usr/local/bin

This answer has information on why /usr/bin is protected.

Rendering answered 22/5, 2018 at 1:28 Comment(1)
So does this mean that the pod update info message that says, "CocoaPods 1.10.0 is available. To update use: sudo gem install cocoapods" is incorrect? Is that the root cause of the confusion?Heartache
E
0

For those of you where this solution does not work (like me), here was something that helped me..

For Mac mini m2 (also mb pro M1 tested):

open terminal and

curl -L https://get.rvm.io | bash -s stable

to get rvm...

Reopen the terminal and install ruby via rvm

rvm install ruby-3.1.1 
rvm use ruby-3.1.1 
rvm --default use 3.1.1

Now you can install cocoapods like before..

sudo gem install cocoapods

This was the only solution that helped me.

Electrophotography answered 31/5, 2023 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.