你的 Ruby 版本是 3.0.2,但你的 Gemfile 指定了 3.1.2。

huangapple go评论62阅读模式
英文:

Your Ruby version is 3.0.2, but your Gemfile specified 3.1.2

问题

当我运行bundle install时,没有出现任何错误。但当我尝试运行puma时,出现了以下错误:

Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.0.2-p107) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 95251
Your Ruby version is 3.0.2, but your Gemfile specified 3.1.2
! Unable to load application: SystemExit: exit

但当我运行rbenv local时,得到的结果是:3.1.2

而且ruby -v的输出是:ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

而我的Gemfile中包含了 ruby "3.1.2"

为什么Puma仍然认为它应该是3.0.2呢?值得注意的是,我用sudo运行Puma,因为我希望能够在0.0.0.0上的端口443上运行https。当我仅运行rails server时,一切都正常,Puma显示的是3.1.2,与预期一致。

我已经查看了其他类似的问题,但没有找到任何解决方法。

英文:

When I run bundle install, I get no errors. But when I try to run puma, I get the error:

Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.0.2-p107) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 95251
Your Ruby version is 3.0.2, but your Gemfile specified 3.1.2
! Unable to load application: SystemExit: exit

but when I run rbenv local, I get: 3.1.2

and ruby -v gives: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

and my Gemfile has ruby "3.1.2"

Why does Puma still think it should be 3.0.2? I should note that I'm running puma with sudo... because I want to have the ability to run https on port 443 at 0.0.0.0 - when I run rails server all by itself, everything works fine and Puma shows 3.1.2 as expected.

I've looked through other similar questions and I haven't found anything that works.

答案1

得分: 1

在我看到的开发和部署设置中,Ruby服务器通常不直接运行在端口443上。据我所知,这样做相当不寻常。相反,通常使用一个较高的端口,这不需要 root 访问权限。在部署中,端口443通常由位于Ruby进程前面的代理服务器(如Nginx或Envoy)提供服务。

我很难复现你的问题。我能看到我们设置之间的一个关键区别是,在你的环境中,sudo which ruby 显示 /usr/bin/ruby(系统Ruby),而我得到的是 /home/brendan/.rbenv/shims/ruby(rbenv Ruby)。这可能是因为在你的 sudo 环境中 $HOME/.rbenv/shims 目录没有包含在 PATH 环境变量中。也许适用的 rbenv init 命令 在那里没有运行?请检查是否遵循了这些 rbenv 安装说明。

你可以通过以下方式更清晰地查看你的 sudo 环境中 $PATH 的条目:

sudo env | grep PATH | sed s/^PATH=// | tr : '\n' | sort

正如评论中所提到的,当运行来自 gem 的可执行文件时,始终要使用 bundle exec 作为前缀,以确保你使用的是 Gemfile.lock 中的版本以及其依赖项。而且,当使用Ruby版本管理器(如rbenv)时,要避免使用系统包管理器安装的Ruby,以避免问题。

如果你坚持要使用端口443和因此需要使用 sudo,我相信有办法让它正常工作;但我建议通过使用不同的端口号来完全避开这个问题。如果有某些需要你使用443端口的情况,也许你应该寻找一种解决该问题的方法。

英文:

In the development and deployment setups I've seen, the Ruby server is not run on port 443 directly. As far as I'm aware, doing that is quite unusual. Instead, a higher port is used, which doesn't require root access. In deployment, port 443 would be served by a proxy in front of the Ruby process, like Nginx or Envoy.

I'm struggling to reproduce your issue. The key difference I can see between our setups is that for you, sudo which ruby shows /usr/bin/ruby (system Ruby), whereas I get /home/brendan/.rbenv/shims/ruby (rbenv Ruby). This is probably due to the $HOME/.rbenv/shims directory not being part of the PATH environment variable within your sudo environment. Perhaps the applicable rbenv init command is not running there? Check you've followed these rbenv installation instructions.

You can more readably view the entries within your sudo environment's $PATH with:

sudo env | grep PATH | sed s/^PATH=// | tr : '\n' | sort

As said in the comments, when running an executable from a gem, always prefix it with bundle exec to ensure you're using the version of it and its dependencies that are in your Gemfile.lock. And to avoid headaches when using a Ruby version manager (like rbenv), avoid using the Ruby that's installed by your system package manager.

If you feel you must use port 443 and hence sudo, I'm sure there's a way to get that to work; but I'd recommend side-stepping the issue entirely by using a different port number. If there is something requiring you to use 443, perhaps you should be looking for a way to address that issue instead.

答案2

得分: 0

首先确保您已安装 Ruby 3.1.2(您可以使用 rbenv 或 rvm 安装)。

然后将其设置为默认版本。

3.1.2 存储在您的项目目录下的 .ruby-version 文件中。

清理 Gemfile.lock。

运行 Bundle install。

英文:

Firstly make sure you have installed ruby 3.1.2 (you can install using rbenv or rvm)

Then make it default

Store 3.1.2 in .ruby-version file under your project directory

Clean the Gemfile.lock

Bundle install

huangapple
  • 本文由 发表于 2023年3月12日 07:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定