I think I installed rvm correctly. When I type in rvm -v it outputs

rvm 1.25.33 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

However, I am trying to install the gem rspec. I type in

gem install rspec

but the output is

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

What should I do? What is going wrong? I can't understand the rvm docs either!


RVM controls which Ruby your current shell points to, but it doesn't install a user-controlled Ruby for you by default. If you haven't installed any specific Ruby versions via RVM, the only Ruby you have is the one OS X installed and that requires sudo permissions to write to.

You can see available Rubies with:

> rvm list

rvm rubies

=* ruby-2.1.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

In my case I have 2.1.2 installed and it's both the current Ruby and the default Ruby when I start a new shell:

> which ruby

To install a Ruby version with RVM do:

> rvm install ruby-2.1
No binary rubies available for: osx/10.10/x86_64/ruby-2.1.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Install of ruby-2.1.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

Now that you have an RVM-managed Ruby installed that's owned by you specifically you can gem-install anything you like without needing to use sudo:

> rvm list

rvm rubies

 * ruby-2.1.2 [ x86_64 ]
=> ruby-2.1.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default
> rvm gemdir
> gem install packer-config

That gem has been installed for the 2.1.3 version of Ruby that RVM put under ~/.rvm for me. If I was to switch to the 2.1.2 version via rvm use ruby-2.1.2 I would not see that gem, I'd have to re-install it to make it available to that Ruby version.

You can also manage gems as sets so they're not even shared with a Ruby install. See the gemset basics on the RVM web site for more details.

| improve this answer | |

That command is trying to install the gem in the global directory (available to every user on the computer), if that's what you want then execute the command with sudo. But if you just want to install rspec you can do gem install rspec.

You can check if you are using the gem executable from rvm by doing which gem if it shows a function then it's from rvm. If the output is a path then do rvm use default.

| improve this answer | |
  • I am doing gem install rspec, but the error message arises. Any suggestions? – Jwan622 Oct 20 '14 at 14:55
  • Oh, that error means that you're using the system's ruby and not the one provided by rvm. Check the rvm troubleshooting guide – Ammar Alammar Oct 20 '14 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .