You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行bundle exec rails console报cannot load such file -- listen错误如何解决

问题根因
  • 直接执行bundle exec rails c默认会加载development环境配置,而ElasticBeanstalk生产环境执行bundle安装时默认跳过了development/test分组的gem,listen仅在development分组声明,因此触发加载缺失错误
  • 手动指定RAILS_ENV=production启动控制台时,SSH登录的shell默认未加载ElasticBeanstalk预设的生产环境变量(包括RDS连接配置),因此数据库连接尝试走本地默认Unix socket,触发连接失败错误
解决方案

每次通过SSH登录EC2实例后,先执行以下命令加载ElasticBeanstalk的生产环境变量:

source /opt/elasticbeanstalk/support/envvars

再执行生产环境控制台启动命令即可:

RAILS_ENV=production bundle exec rails c

也可以直接合并为一行命令执行:

source /opt/elasticbeanstalk/support/envvars && RAILS_ENV=production bundle exec rails c

内容的提问来源于stack exchange,提问作者Imran Ahmad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 15:24:04