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

I keep receiving this error and I don’t know how to fix it. I came across this error when trying the “sudo gem install cocoapods” command. I’ve researched for 2 weeks at least 1 hour a day. Found a lot of websites that had some solutions that I could try but ultimately I keep receiving the error. If anyone else has encountered the problem, any advise would be appreciated.


I was reading a StackOverflow thread myself and this installation command might be of help:

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

The thread made the point of saying that you should not be attempting to install cocoapods in /usr/bin.