在终端中:#rails 有效,但 #sudo Rails 无效 -RVM Gemset

发布于 2024-11-04 06:00:32 字数 1546 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2024-11-11 06:00:32

这可能是您的问题:

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

删除该文件(可能通过 sudo)以及可能在 sudo 下创建的任何其他临时文件。然后你应该能够像你一样运行 Rails,而不需要 sudo。混合两者总会给你带来权限方面的麻烦。

或者,只需在 Rails 根目录中运行 sudo chown -R alec:alec . (或您所在的组)即可将所有所有权重置为您自己。

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.

再可℃爱ぅ一点好了 2024-11-11 06:00:32

根据您的 /etc/sudoers 和发行版的默认 sudo 版本,sudo 很可能不会保留您的 PATH(以及其他环境变量)。有几个选项:

  1. 配置 /etc/sudoers 以保留您想要的环境变量,尽管对于 PATH 您可能会遇到问题: sudo 更改 PATH - 为什么?
  2. 以 root 身份安装 rvm,系统范围内的所有用户都
  3. 使用 rvmsudo

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文