执行vagrant up失败:invalid byte sequence in UTF-8 (ArgumentError)
Vagrant up 执行时UTF-8编码错误的解决方案
这个UTF-8编码错误我在Windows环境下碰到过好几次,给你几个针对性的排查和解决思路:
1. 检查工作目录路径是否含非ASCII字符
Vagrant基于Ruby开发,而Ruby在Windows下对含中文、特殊符号的路径兼容性很差。确保你的Vagrantfile所在的文件夹路径全是英文和数字,比如把D:/我的项目/vagrant改成D:/my-project/vagrant,之后重新在新路径下执行vagrant up。
2. 清理并重新导入CentOS 6.9 Box
有时候下载的Box文件损坏或者编码异常,导致导入失败:
- 先删除现有Box:
vagrant box remove centos69 - 重新从官方源导入(或者换国内镜像源加快速度):
vagrant box add centos69 https://vagrantcloud.com/centos/boxes/6.9/versions/20180102.0.0/providers/virtualbox.box
3. 设置Ruby编码环境变量
强制Vagrant内嵌的Ruby使用UTF-8编码:
- 右键「此电脑」→ 属性 → 高级系统设置 → 环境变量
- 点击「系统变量」下的「新建」,添加:
- 变量名:
RUBYOPT - 变量值:
-E UTF-8:UTF-8
- 变量名:
- 关闭所有命令行窗口,重新打开后执行
vagrant up
4. 升级Vagrant和VirtualBox版本
你的Vagrant 2.1.1和VirtualBox 5.2都是较旧的版本,新版本修复了很多Windows下的编码兼容问题:
- 升级Vagrant到最新稳定版
- 升级VirtualBox到6.x或7.x(注意Vagrant最新版支持对应VirtualBox版本)
你遇到的报错信息:
> vagrant up Bringing machine 'node1' up with 'virtualbox' provider... ==> node1: Importing base box 'centos69'... C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/driver/base.rb:408:in `block in execute': invalid byte sequence in UTF-8 (ArgumentError) from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/util/retryable.rb:17:in `retryable' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/driver/base.rb:383:in `execute' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/driver/version_5_0.rb:311:in `import' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/action/import.rb:53:in `import' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/action/import.rb:13:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb:17:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builtin/prepare_clone.rb:15:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/action/customize.rb:40:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/virtualbox/action/check_accessible.rb:18:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builder.rb:116:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/runner.rb:66:in `block in run' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/util/busy.rb:19:in `busy' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/runner.rb:66:in `run' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builtin/call.rb:53:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builtin/config_validate.rb:25:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builtin/handle_box.rb:56:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builder.rb:116:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/runner.rb:66:in `block in run' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/util/busy.rb:19:in `busy' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/runner.rb:66:in `run' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/builtin/call.rb:53:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/lib/vagrant/action/warden.rb:34:in `call' from C:/HashiCorp/Vagrant/embedded/gems/2.1.1/gems/vagrant-2.1.1/plugins/providers/
内容的提问来源于stack exchange,提问作者d-_-b
相关产品推荐
相关产品推荐

