vagrant up報錯【io.rb:32:in `encode': "\x95" followed by """ on GBK (Encoding::InvalidByteSequenceError)】
這幾天在學習虛擬機的相關知識扬霜,在使用VirtualBox和Vagrant創(chuàng)建虛擬機時踩了一些坑,在網上搜索到的解決方案雖然給了我一些幫助,但是沒有完全解決問題∨涡現在就將我的問題記錄下來屁倔,希望給新入坑的人一些幫助赖阻。
第一步,安裝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改成你給你的虛擬環(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\七月的風>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發(fā)現還是報同樣的錯誤扬跋,這是為什么呢。
解決方案:經過一番琢磨我發(fā)現凌节,雖然我將路徑目錄全改成了英文钦听,但是這幾個文件是在中文目錄下生成的洒试,所以檢測到的還是中文,所以還會報亂碼錯誤朴上。所以我索性將這幾個文件全刪除了垒棋,然后將軟件卸載了,重新安裝痪宰。一切ok叼架。
如果你還出現了下面這種報錯:
==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就大功告成了
]