升级ElasticBeanstalk平台后出现puma: command not found错误
解决方案
1. 修改Procfile使用bundle exec执行puma
将Procfile中的命令修改为:
web: bundle exec puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb
新版本的Elastic Beanstalk Amazon Linux 2023平台(4.3.1)调整了Ruby环境的PATH配置,默认不会把bundle安装的gem可执行文件路径加入全局PATH。直接调用puma会找不到命令,而bundle exec会通过项目的bundle上下文定位到正确的puma可执行文件。
2. 通过.ebextensions配置全局PATH
创建或更新.ebextensions/puma-path.config文件,添加以下内容:
container_commands: 01_set_bundle_path: command: 'echo "export PATH=$HOME/.bundle/bin:$PATH" >> /etc/profile.d/bundle-path.sh'
这个配置会在部署时把bundle的可执行文件目录加入系统全局PATH,确保后续可以直接调用puma命令。
3. 确认Gemfile的puma依赖
检查项目的Gemfile,确保已明确声明puma依赖:
gem 'puma', '6.5.0'
虽然日志显示puma已安装,但明确版本可以避免bundle安装不符合预期的版本,同时确保部署过程中依赖被正确加载。
原因说明
Elastic Beanstalk的Ruby平台版本4.3.1相比4.0.0,对Ruby运行环境的PATH做了调整,不再默认包含bundle安装的gem的bin目录。这导致直接调用puma命令时,系统无法找到对应的可执行文件,即使bundle已经成功安装了puma。
内容的提问来源于stack exchange,提问作者darkinsyde
相关产品推荐
相关产品推荐

