This question already has an answer here:
-
Installing gem or updating RubyGems fails with permissions error
25 answers
I updated my Mac OS to 10.9 Mavericks yesterday. My current Ruby version shows as
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
I got Rails installed on my machine and when I try to install gems I get the following message:
Fetching: eventmachine-1.0.3.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I am trying all this in my home directory. Any suggestions?
Use a Ruby version manager, like RVM or rbenv.
I can't speak for rbenv, but RVM prepends a Ruby version-specific bin
to your PATH
that you have access to, so you don't have to use sudo
(which is how you could install gems in your current situation, but is highly discouraged).
rbenv similarly prepends to your $PATH
, but it uses a shim.
When I had this same error it was because I did not have a Ruby version manager installed, it defaulted to the Ruby version that came shipped with my computer which is owned root.
Since it is a very bad idea to use sudo
to install gems, I installed RVM with Ruby 2.1.2
\curl -sSL https://get.rvm.io | bash -s stable --ruby=2.1.2
then made sure that it was being used as the default by running
rvm use ruby-2.1.2
RVM creates a new location to store your Ruby and gems with your user permissions so you don't have to use sudo
or get a permissions error. The new gem location is:
~/.rvm/gems
Then carry on as you were...
gem install ....
I do not have RVM installed. I got this error because I installed rbenv but did not run rbenv init
yet.
After I inserted the contents from the command rbenv init
into .bash_profile, gem install
works as expected.
I also happened to set rbenv global <ruby-version>
to a downloaded Ruby version first.
Just like to say to you all after wasting a good hour or more on trying to install RubyGems... to rubygems-2.4.5 'sudo' got me through!
It works a treat...