vagrant up报错【io.rb:32:in `encode': "\x95" followed by "\"" on GBK (Encoding::InvalidByteSequenceE...

vagrant up报错【io.rb:32:in `encode': "\x95" followed by """ on GBK (Encoding::InvalidByteSequenceError)】

这几天在学习虚拟机的相关知识,在使用VirtualBox和Vagrant创建虚拟机时踩了一些坑,在网上搜索到的解决方案虽然给了我一些帮助,但是没有完全解决问题。现在就将我的问题记录下来,希望给新入坑的人一些帮助。

第一步,安装VirtualBox和Vagrant。没啥问题,顺利进行(注意:安装VirtualBox之前要开启电脑的虚拟化,这里就不在赘述了)

第二步,也没有问题


C:\Users\qiyue>vagrant init centos7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

/**
  *由于vagrant是国外的网站,直接使用vagrant up由于网速太慢大概率会失败,所以我先将centos7.box
  *下载下来通过命令添加
  */
C:\Users\qiyue>vagrant box add --name centos7 d:\guliSoft\centos7.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos7' (v0) for provider:
    box: Unpacking necessary files from: file:///d:/guliSoft/centos7.box
    box:
==> box: Successfully added box 'centos7' (v0) for 'virtualbox'!

注意:如果只使用vagrant init命令在后面vagrant up会报错
==default: Box 'base' could not be found. Attempting to find and install...==

C:\Vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'base' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'base' (v0) for provider: virtualbox
    default: Downloading: base
    default:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

这时候就需要你手动去改用户目录下的.Vagrantfile文件,使用记事本打开它,将config.vm.box = "base"中的base改成你给你的虚拟环境起的名称。这个问题就这样解决了。

第三步:
==D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/io.rb:32:in `encode': "\xA3\x8E" from GBK to UTF-8 (Encoding::UndefinedConversionError)==

C:\Users\七月的风>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos7'...
D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/io.rb:32:in `encode': "\xA3\x8E" from GBK to UTF-8 (Encoding::UndefinedConversionError)
        from D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/io.rb:32:in `read_until_block'
        from D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/subprocess.rb:242:in `block in execute'
        from D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/subprocess.rb:240:in `each'

这里就是我们踩的第一个坑:

这里从网上百度很容易知道,是由于C:\Users\七月的风>这个目录下混入了中文导致的,然后我们将这里改成C:\Users\qiyue>,然后重新vagrant up发现还是报同样的错误,这是为什么呢。

微信图片_20210120225200.png

解决方案:经过一番琢磨我发现,虽然我将路径目录全改成了英文,但是这几个文件是在中文目录下生成的,所以检测到的还是中文,所以还会报乱码错误。所以我索性将这几个文件全删除了,然后将软件卸载了,重新安装。一切ok。

6.png

如果你还出现了下面这种报错:

==D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/io.rb:32:in `encode': "\x95" followed by """ on GBK (Encoding::InvalidByteSequenceError)==

解决方案:这时候你要到D:/guliSoft/HashiCorp/Vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/io.rb目录下找到地32行,将这行注释掉,下面加入参考github上的代码。

 #data << io.readpartial(READ_CHUNK_SIZE).encode("UTF-8", Encoding.default_external)
  data << io.readpartial(READ_CHUNK_SIZE).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')

然后vagrant up就大功告成了


微信图片_20210120231416.png

]

你可能感兴趣的:(vagrant up报错【io.rb:32:in `encode': "\x95" followed by "\"" on GBK (Encoding::InvalidByteSequenceE...)