Ruby -Gems Env-编码错误(Windows)
我已经在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是Ruby中的一个错误,或者更具体地说是Bundler。我将其报告为错误。
同时,您可以尝试设置
gem_home
。它应该是其余文件夹的基础设置。还有gem_spec_cache
,它允许您分别移动缓存文件夹。但是,您遇到的错误来自Bundler,当它运行
global_config_file
。从那里我们可以看到您可能需要设置
bundle_config
或bundle_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 alsoGEM_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
orBUNDLE_USER_CONFIG
. I looks like it may be enough just to set one of these to point to a dummy location. For exampleC:\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.
rubyinstaller提出了一个争论
rubyinstaller takes a DIR argument