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

执行rails server webrick报Thor::InvocationError错误如何解决

Debian系统Redmine启动Rails服务报参数错误故障解决

故障复现

在/opt/redmine目录下执行启动命令:

redmine@Debian:/opt/redmine$ bundle exec rails server webrick -e production

抛出核心报错:

/opt/redmine/vendor/bundle/ruby/2.7.0/gems/railties-6.1.6/lib/rails/commands/server/server_command.rb:130:in `perform': wrong number of arguments (given 1, expected 0) (ArgumentError)
        9: from bin/rails:4:in `<main>'
        8: from bin/rails:4:in `require'
        7: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/railties-6.1.6/lib/rails/commands.rb:18:in `<top (required)>'
        6: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/railties-6.1.6/lib/rails/command.rb:48:in `invoke'
        5: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/railties-6.1.6/lib/rails/command/base.rb:69:in `perform'
        4: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        3: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        2: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:20:in `run'
        1: from /opt/redmine/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:34:in `rescue in run'
/opt/redmine/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:525:in `handle_argument_error': ERROR: "rails server" was called with arguments ["webrick"] (Thor::InvocationError)
Usage: "rails server -u [thin/puma/webrick] [options]"

卸载重装Rails无法解决问题。

故障根因

报错末尾已经给出了正确的命令格式,重装Rails属于无效操作,问题和安装包损坏无关:
Rails 6.1版本调整了rails server子命令的参数规则:

  • Rails 6.0及更早版本支持直接将webrick、puma、thin这类Web服务器名作为位置参数,跟在rails server后面传入
  • Rails 6.1及之后版本,指定Web服务器必须通过-u(全称--using)参数显式声明,直接传入服务器名会被识别为非法多余参数,触发参数数量不匹配的报错。

解决方法

核心修复

调整启动命令的参数格式,用-u指定webrick服务器即可:

bundle exec rails server -u webrick -e production

如果不需要强制使用webrick,Redmine默认自带puma服务器依赖,直接执行以下命令即可正常启动,不需要额外指定服务器:

bundle exec rails server -e production

依赖补全(可选)

如果执行修正后的命令提示找不到webrick依赖,是因为Rails 6.1之后不再默认绑定webrick组件,手动添加即可:

  1. 打开Redmine根目录下的Gemfile文件,新增一行配置:
    gem 'webrick'
    
  2. 执行命令安装新增的依赖:
    bundle install
    
  3. 重新执行修正后的启动命令即可。

后续排查项

如果调整命令后仍启动失败,按以下顺序检查:

  • 确认执行命令的用户为redmine用户,对/opt/redmine目录拥有完整读写权限,禁止直接用root用户启动Redmine服务
  • 确认生产环境数据库配置、secret_key_base配置已正确写入config/database.yml、config/secrets.yml文件
  • 执行bundle exec rails db:migrate RAILS_ENV=production确认所有数据库迁移脚本执行完成,无未同步的数据库结构变更

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 20:45:36