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

Ubuntu环境下无法执行bundle update或bundle install问题求助

问题:WSL Ubuntu环境下执行bundle操作无法克隆GitHub仓库

我在Windows 10.0.19042系统的WSL Ubuntu 20.04.5 LTS环境部署Ruby应用,执行bundle install或bundle update时均遇到以下错误:

djob@mylocal-LTW:/mnt/c/Users/djob/workspace/heroku/fix-store$ /usr/local/bin/bundle update --verbose
Fetching git://github.com/spree/spree_gateway.git
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone 'git://github.com/spree/spree_gateway.git' "/home/djob/.bundler/cache/git/spree_gateway-6119aa63b6a7211640621de5f05ec34760ee7fe4" --bare --no-hardlinks --quiet due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/spree/spree_gateway.git' "/home/djob/.bundler/cache/git/spree_gateway-6119aa63b6a7211640621de5f05ec34760ee7fe4" --bare --no-hardlinks --quiet` in directory /mnt/c/Users/djob/workspace/heroku/fix-store has failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone 'git://github.com/spree/spree_gateway.git' "/home/djob/.bundler/cache/git/spree_gateway-6119aa63b6a7211640621de5f05ec34760ee7fe4" --bare --no-hardlinks --quiet due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/spree/spree_gateway.git' "/home/djob/.bundler/cache/git/spree_gateway-6119aa63b6a7211640621de5f05ec34760ee7fe4" --bare --no-hardlinks --quiet` in directory /mnt/c/Users/djob/workspace/heroku/fix-store has failed.

确认该GitHub仓库存在,我的Ruby版本为2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu],Gemfile内容如下:

source 'https://rubygems.org'

ruby '2.7.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
gem 'puma'

gem 'pg'

gem 'rails_12factor', group: :production
gem 'rack-cors'

gem 'aws-sdk', '~> 1.0'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end


gem 'spree', '3.0.4'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'

gem 'dalli'

可能的根本原因及解决方法

根本原因

  • Git协议端口被拦截:Bundler解析github:源时默认使用git://协议,该协议使用9418端口,很多网络环境(公司防火墙、公共网络)会拦截这个端口,导致无法克隆仓库。
  • WSL网络配置异常:WSL的网络可能未同步Windows主机的代理设置,或者Windows防火墙阻止了WSL发起的网络请求,导致无法连接GitHub。
  • 版本兼容性问题:你使用的Ruby 2.7.0相对较新,但Gemfile中的Rails 4.2.4是老旧版本,高版本Bundler与老旧Rails版本可能存在兼容性问题,导致处理Git源时出错。

解决方法

1. 替换为HTTPS协议克隆

修改Gemfile中两个Spree相关gem的源,显式指定HTTPS地址,避免使用被拦截的git协议:

gem 'spree', '3.0.4'
gem 'spree_gateway', git: 'https://github.com/spree/spree_gateway.git', branch: '3-0-stable'
gem 'spree_auth_devise', git: 'https://github.com/spree/spree_auth_devise.git', branch: '3-0-stable'

修改后执行bundle install重试。

2. 排查WSL网络问题

  • 在WSL终端执行curl https://github.com,测试是否能正常连通GitHub。如果无法连通,检查:
    • Windows主机的代理设置,在WSL中同步代理环境变量:
      export http_proxy=http://你的代理IP:端口
      export https_proxy=http://你的代理IP:端口
      
    • 临时关闭Windows防火墙,测试是否是防火墙阻止了WSL的网络请求。

3. 适配Bundler版本

Rails 4.2.4与Bundler 2.x版本兼容性较差,建议安装Bundler 1.x系列版本:

gem uninstall bundler
gem install bundler -v 1.17.3

安装完成后重新执行bundle install。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 18:31:08