Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use sudo for gem install cocoapods

Tags:

ruby

gem

When I run

$ gem install cocoapods

I get

Fetching: i18n-0.7.0.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

I've read this post cocoaPods pod install Permission denied but the answer there doesn't say whether it is correct to run sudo on your gem install (despite being asked in the Question - i.e. Is sudo installation of cocoaPods the wrong way or normal way? ).

like image 352
Snowcrash Avatar asked Jan 02 '15 11:01

Snowcrash


People also ask

What is gem install CocoaPods?

CocoaPods manages library dependencies for your Xcode project. You specify the dependencies for your project in one easy text file. CocoaPods resolves dependencies between libraries, fetches source code for the dependencies, and creates and maintains an Xcode workspace to build your project.

Should I install CocoaPods with GEM or homebrew?

If you try to install a gem through pre-installed Ruby, you've to use sudo by default witch is not a good practice. Another option is to install CocoaPods in your user-level directory by following instructions available on the Sudo-less installation section. I would suggest you install CocoaPods using brew .


1 Answers

It seems you are not using any package manager. Since, you don't have write permission to this directory, there is nothing wrong in using sudo for gem install.

However, I prefer changing ownership of that directory, so that I don't have to use sudo every time.
i.e. sudo chown -R [login name] /Library/Ruby/Gems/2.0.0

and ensure that I have write permission. sudo chmod -R u+w /Library/Ruby/Gems/2.0.0

Consider using rvm (ruby version manager) or rbenv

like image 120
Sahil Avatar answered Oct 14 '22 04:10

Sahil