Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "write permission" errors installing Rails?

When I use rvm use 1.9.2, I get Rails v3.0.0:

vikas@admin1-DL-H61MXEL:~$ rvm use 1.9.2 --default
Using /home/vikas/.rvm/gems/ruby-1.9.2-p320
vikas@admin1-DL-H61MXEL:~$ rails -v
Rails 3.0.0

When I use rvm use 2.0.0, I get Rails v3.2.13:

vikas@admin1-DL-H61MXEL:~$ rvm use 2.0.0
Using /home/vikas/.rvm/gems/ruby-2.0.0-p195
vikas@admin1-DL-H61MXEL:~$ rails -v
Rails 3.2.13

I need Rails v3.2.13 with Ruby 1.9.2.

When I used rvm use 1.9.2 --default and gem install rails -v 3.2.13, I got the following error:

While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /home/vikas/.rvm/gems/ruby-1.9.2-p320/bin directory. 

This is the error I'm facing now.
like image 499
VIKKY Avatar asked Jul 04 '13 06:07

VIKKY


1 Answers

The most likely reason you're getting the error:

(Gem::FilePermissionError) You don't have write permissions into the /home/vikas/.rvm/gems/ruby-1.9.2-p320/bin directory. 

Is because, at some point, you used sudo or were running as root when you use RVM to install a gem. When that happened, the ownership of files and/or folders changed to root's permissions, which you can't override running as you.

You don't want to run as root, or use sudo EVER when running rvm or gem commands if you have a RVM installation to provide Ruby in a sandbox in your home directory.

To fix this, try this command:

sudo chown -R vikas ~/.rvm

That will use sudo to change ownership of all files in the ~/.rvm directory to your own account, from the "root" user. This will take at least a few seconds so let it run.

Once that has run, you should be able to switch to each of your Rubies and delete the installed Rails:

rvm use 1.9.2
gem uninstall rails
gem install rails -v 3.2.13

Then:

rvm use 2.0.0
gem uninstall rails
gem install rails -v [whatever version you want]
gem install rails -v 
like image 99
the Tin Man Avatar answered Sep 28 '22 15:09

the Tin Man