在终端中:#rails 有效,但 #sudo Rails 无效 -RVM Gemset
alec@Locke:~/workspace/rails/nwis$rails -v 铁轨3.0.7 alec@Locke:~/workspace/rails/nwis$ sudo Rails -v sudo:rails:找不到命令
我需要使用sudo,因为当我尝试在我的计算机上运行rails服务器时出现权限被拒绝错误。
我认为这是 RVM 和使用 Gemsets 的问题,但我不知道为什么。我尝试对每个命令使用 sudo 重新运行 Gemset 设置过程,以确保我的 root 用户和普通用户位于同一页面上,但这给了我相同的结果。
明确为什么我要以 sudo 身份运行;当尝试启动 Rails 服务器时,会发生以下情况:
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'
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>'`
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'
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>'`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是您的问题:
删除该文件(可能通过 sudo)以及可能在 sudo 下创建的任何其他临时文件。然后你应该能够像你一样运行 Rails,而不需要 sudo。混合两者总会给你带来权限方面的麻烦。
或者,只需在 Rails 根目录中运行
sudo chown -R alec:alec .
(或您所在的组)即可将所有所有权重置为您自己。Here's your problem, probably:
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.根据您的 /etc/sudoers 和发行版的默认 sudo 版本,sudo 很可能不会保留您的 PATH(以及其他环境变量)。有几个选项:
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: