vagrant up報錯【io.rb:32:in `encode': "\x95" followed by """ on GBK (Encoding::InvalidByteSequenceError)】
這幾天在學(xué)習(xí)虛擬機的相關(guān)知識,在使用VirtualBox和Vagrant創(chuàng)建虛擬機時踩了一些坑,在網(wǎng)上搜索到的解決方案雖然給了我一些幫助,但是沒有完全解決問題?,F(xiàn)在就將我的問題記錄下來,希望給新入坑的人一些幫助。
第一步,安裝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是國外的網(wǎng)站,直接使用vagrant up由于網(wǎng)速太慢大概率會失敗,所以我先將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改成你給你的虛擬環(huán)境起的名稱。這個問題就這樣解決了。
第三步:
==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\七月的風(fēng)>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'
這里就是我們踩的第一個坑:
這里從網(wǎng)上百度很容易知道,是由于C:\Users\七月的風(fēng)>這個目錄下混入了中文導(dǎo)致的,然后我們將這里改成C:\Users\qiyue>,然后重新vagrant up發(fā)現(xiàn)還是報同樣的錯誤,這是為什么呢。

解決方案:經(jīng)過一番琢磨我發(fā)現(xiàn),雖然我將路徑目錄全改成了英文,但是這幾個文件是在中文目錄下生成的,所以檢測到的還是中文,所以還會報亂碼錯誤。所以我索性將這幾個文件全刪除了,然后將軟件卸載了,重新安裝。一切ok。

如果你還出現(xiàn)了下面這種報錯:
==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行,將這行注釋掉,下面加入?yún)⒖糶ithub上的代碼。
#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就大功告成了

]