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

WSL2环境下Windows终端执行Ruby/bundle脚本失败,终端内执行正常

问题:WSL2中通过Powershell/CMD执行Ruby相关bash脚本时报错

我在Windows 11的WSL2环境中,通过以下命令成功安装了Ruby:

sudo apt install gnupg2 build-essential dh-autoreconf
gpg --keyserver keyserver.ubuntu.com --recv-keys ...
\curl -sSL https://get.rvm.io | bash
rvm install ruby
gem update
gem install jekyll
gem install bundler

安装完成后,Ruby版本为3.1.3p185(执行ruby --version可查看)。

我的WSL主目录下有test.sh脚本,内容如下:

#!/bin/bash
bundle exec jekyll build

通过Win+R打开bash命令提示符,执行sh test.sh可正常完成Jekyll构建。但在Powershell或Windows CMD中执行bash test.sh时,出现以下错误:

/usr/local/bin/bundle: /usr/bin/ruby2.7: bad interpreter: No such file or directory

其他.sh脚本使用bash script.sh语法均可正常运行,仅涉及Ruby/bundler的脚本出现该问题。我已尝试过相关问题的修复方案(确认bundler已安装),但无效。

补充信息:

  • 改用wsl -e bash test.sh执行仍会出现相同错误
  • 若将test.sh内容改为仅ruby --version,执行时会提示ruby: command not found

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 04:20:18