Ruby -Gems Env-编码错误(Windows)

发布于 2025-02-06 20:16:36 字数 2443 浏览 1 评论 0原文

我已经在Windows上安装了Rubyinstaller的最新Ruby版本,然后通过宝石安装了导轨。

每次我尝试运行rails new App_name命令,我都会收到一个编码错误。

C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:52:in `match?': invalid byte sequence in UTF-8 (ArgumentError)
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:52:in `chop_basename'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:376:in `plus'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:356:in `+'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:422:in `join'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:445:in `global_config_file'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:93:in `initialize'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:343:in `new'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:343:in `settings'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/env.rb:20:in `report'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:71:in `request_issue_report_for'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:50:in `log_error'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:123:in `rescue in with_friendly_errors'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:115:in `with_friendly_errors'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bundler-2.3.15/exe/bundle:36:in `<main>'

我怀疑我的路径可能出了问题,所以我检查了我的gem env,并且看到问题在我的Windows用户文件夹名称中,其中包含特殊字符,显然Ruby不接受它,在我的GEM Env下找到:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.3.15
  - RUBY VERSION: 3.1.2 (2022-04-12 patchlevel 20) [x64-mingw-ucrt]
  - INSTALLATION DIRECTORY: C:/Ruby31-x64/lib/ruby/gems/3.1.0
  - USER INSTALLATION DIRECTORY: C:/Users/Tiago Galv�o/.local/share/gem/ruby/3.1.0
  - RUBY EXECUTABLE: C:/Ruby31-x64/bin/ruby.exe
  - GIT EXECUTABLE: C:\Program Files\Git\cmd/git.EXE
  - EXECUTABLE DIRECTORY: C:/Ruby31-x64/bin
  - SPEC CACHE DIRECTORY: C:/Users/Tiago Galv�o/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:

我试图更改我的用户文件夹名称windows注册表,并且命令确实开始工作。但是,我需要将所有内容都恢复为原始名称,因为我的系统开始表现出奇怪的作用。

所以我的问题是:

  • 如何更改我的gem env的用户安装目录和规格缓存目录,以便能够在Windows中运行Rails命令?我想将文件夹更改为一个没有任何特殊字符的文件夹,甚至让Ruby接受我的名字。

关于我如何实现的想法?

I have installed the latest Ruby version from RubyInstaller on Windows and then installed Rails through gems.

Everytime I try to run rails new app_name command I get an encoding error.

C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:52:in `match?': invalid byte sequence in UTF-8 (ArgumentError)
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:52:in `chop_basename'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:376:in `plus'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:356:in `+'
        from C:/Ruby31-x64/lib/ruby/3.1.0/pathname.rb:422:in `join'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:445:in `global_config_file'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:93:in `initialize'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:343:in `new'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:343:in `settings'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/env.rb:20:in `report'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:71:in `request_issue_report_for'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:50:in `log_error'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:123:in `rescue in with_friendly_errors'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:115:in `with_friendly_errors'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bundler-2.3.15/exe/bundle:36:in `<main>'

I suspected something was probably wrong with my PATH's so I checked my gem env and I saw that the problem lies in my Windows User folder name which has a special character in it and apparently ruby does not accept it, find below my gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.3.15
  - RUBY VERSION: 3.1.2 (2022-04-12 patchlevel 20) [x64-mingw-ucrt]
  - INSTALLATION DIRECTORY: C:/Ruby31-x64/lib/ruby/gems/3.1.0
  - USER INSTALLATION DIRECTORY: C:/Users/Tiago Galv�o/.local/share/gem/ruby/3.1.0
  - RUBY EXECUTABLE: C:/Ruby31-x64/bin/ruby.exe
  - GIT EXECUTABLE: C:\Program Files\Git\cmd/git.EXE
  - EXECUTABLE DIRECTORY: C:/Ruby31-x64/bin
  - SPEC CACHE DIRECTORY: C:/Users/Tiago Galv�o/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:

I have tried to change my User folder name trough the windows registry and the commands indeed start working. However I needed to revert everything to the original name because my system started acting strange.

So my question is:

  • How can I change the USER INSTALLATION DIRECTORY and SPEC CACHE DIRECTORY of my gem env in order to be able to run rails commands in Windows? I would like to change the folder to a folder without any special chars or even to make ruby accept this special char in my name.

Any ideas on how I can accomplish it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2025-02-13 20:16:36

这似乎是Ruby中的一个错误,或者更具体地说是Bundler。我将其报告为错误。

同时,您可以尝试设置gem_home。它应该是其余文件夹的基础设置。还有gem_spec_cache,它允许您分别移动缓存文件夹。

但是,您遇到的错误来自Bundler,当它运行 global_config_file

从那里我们可以看到您可能需要设置bundle_configbundle_user_config。我看起来只足以将其中之一指向一个假人位置。例如c:\虚拟。这将阻止Bundler尝试访问您的用户主目录,这是具有问题的UTF-8字符的主目录。

这些ENV变量之一或它们的组合将有望允许一切工作。

This seems like a bug in Ruby, or more specifically Bundler. I would report it as a bug.

In the meantime you can try setting GEM_HOME. It should be the base setting for the rest of the folders. There is also GEM_SPEC_CACHE, which allows you to move the cache folder separately.

However the error you are getting is from Bundler, when it is running global_config_file.

From there we can see that you might want to set BUNDLE_CONFIG or BUNDLE_USER_CONFIG. I looks like it may be enough just to set one of these to point to a dummy location. For example C:\Dummy. This will prevent Bundler from trying to access your user home directory, which is the one with the problematic UTF-8 character.

One of those env variables, or a combination of them, will hopefully allow everything to work.

你没皮卡萌 2025-02-13 20:16:36

rubyinstaller提出了一个争论

rubyinstaller-w.x.y-z-x64.exe /DIR="%ProgramFiles%\Ruby"

rubyinstaller takes a DIR argument

rubyinstaller-w.x.y-z-x64.exe /DIR="%ProgramFiles%\Ruby"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文