乘客无法加载 rbenv 托管版本

Passenger cannot load rbenv managed versions

一个服务器有两个用户。 deploy 有 sudo 权限,guest 没有。 来宾有一个应用程序正在迁移 ruby 个版本(从 2.3.4 到 2.4.5)。

最初,来宾安装 2.4.5 版后乘客无法启动,因为它没有找到此版本 ruby。 deploy 不得不安装它。但是,启动服务器的下一阶段无法加载应用程序,同时确认它正在 deploy 用户目录

中寻找 ruby 的版本
Error: The application encountered the following error: cannot load such file -- bundler/setup (LoadError)
/home/deploy/.rbenv/versions/2.4.5/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/deploy/.rbenv/versions/2.4.5/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:363:in `activate_gem'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:221:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:527:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:220:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-loader.rb:86:in `load_app'
/usr/share/passenger/helper-scripts/rack-loader.rb:116:in `block in <module:App>'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
/usr/share/passenger/helper-scripts/rack-loader.rb:115:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-loader.rb:28:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-loader.rb:27:in `<main>'

passenger-config --ruby-command 似乎在寻找合适的目录,

passenger-config was invoked through the following Ruby interpreter:
  Command: /home/guest/.rbenv/versions/2.4.5/bin/ruby
  Version: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]

然而,

rbenv exec gem environment gemdir

returns

/home/guest/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0

如何解决这个问题?

此处的问题与不同的用户和调用的 ruby 个版本有关。

passenger-config --ruby-command

returns 有趣的段落,在这种情况下:

 To use in Nginx : passenger_ruby /home/guest/.rbenv/versions/2.4.5/bin/ruby

虽然 nginx/sites-enabled/relevant_application 文件不需要为单个用户调用该命令,但对于多个用户则需要此命令。然后重启nginx!