开发者

In Terminal: #rails works but #sudo rails does not -RVM Gemset

开发者 https://www.devze.com 2023-03-02 16:26 出处:网络
alec@Locke:~/workspace/rails/nwis$ rails -v Rails 3.0.7 alec@Locke:~/workspace/rails/nwis$ sudo rails -v

alec@Locke:~/workspace/rails/nwis$ rails -v Rails 3.0.7 alec@Locke:~/workspace/rails/nwis$ sudo rails -v sudo: rails: command not found

I need to use sudo because I have a permission denied error when I try to run rails server on my machine.

I think it's an issue with RVM and using Gemsets, but I don't know why. I've tried re-running the Gemset setup process using sudo for each command to make sure my root user and my regular user are on the same page, but that gave me the same result.

To be clear as to why I am running as sudo; when trying to start a rails server, this is what happens:

rails server
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/alec/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:267:in `initialize': Permission     denied - /home/alec/workspace/rails/nwis/tmp/pids/server.pid (Errno::EACCES)
    from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:267:in `open'
    from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:267:in `write_pid'开发者_Go百科
from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:203:in `start'
from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/server.rb:65:in `start'
from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
from /home/alec/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'`


Here's your problem, probably:

Permission     denied - /home/alec/workspace/rails/nwis/tmp/pids/server.pid

Remove that (probably via sudo) and any other temporary files that may have been created under sudo. Then you should be able to run rails as you, without sudo. Mixing the two will always give you permissions troubles.

Or alternatively, just run sudo chown -R alec:alec . (or whatever your group is) in your rails root directory to reset all ownerships to yourself.


Depending on your /etc/sudoers and your distro's default build of sudo, it's quite possible that sudo doesn't keep your PATH (as well as other environment variables). There are a few options:

  1. configure /etc/sudoers to keep the environment variables you want, although for PATH you'll likely run into issues: sudo changes PATH - why?
  2. install rvm as root, systemwide for all users
  3. use rvmsudo
0

精彩评论

暂无评论...
验证码 换一张
取 消