Why do I get “write permission” errors installing

2019-04-28 19:19发布

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.

3条回答
Rolldiameter
2楼-- · 2019-04-28 19:52
rvm use 1.9.2 --default Using /home/vikas/.rvm/gems/ruby-1.9.2-p320 
gem install rails -v 3.2.13
查看更多
Summer. ? 凉城
3楼-- · 2019-04-28 20:03

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 
查看更多
冷血范
4楼-- · 2019-04-28 20:08

rvm is software tool by which you can manage multiple version of rubies on your system.

for each ruby version you can create a gemset which is just a group of gems.

each ruby version you install has a 'default' gemset.

and it seems that you have installed rails 3.0 for ruby 1.9.2 and rails 3.2.13 for ruby 2.0

you can create your own gemset by command

rvm gemset create rails3

this will create a gemset named 'rails3' and to use it you have to do

rvm gemset use rails3

and in this gemset you can install any version of rails you want.

with command

gem install rails -v='3.2.13'

for more info see rvm doc.

https://rvm.io/

查看更多
登录 后发表回答