1. 程式人生 > >Ubuntu 18.04 安裝 vagrant & VirtualBox

Ubuntu 18.04 安裝 vagrant & VirtualBox

在 Ubuntu 18.04 環境下,安裝 vagrant 十分簡單,只需執行以下命令: 

# apt install virtualbox -y
# wget -c https://releases.hashicorp.com/vagrant/2.0.3/vagrant_2.0.3_x86_64.deb
# dpkg -i vagrant_2.0.3_x86_64.deb
# vagrant plugin install vagrant-vbguest

驗證是否安裝成功:

去官方網站下載一個 box 映象,http://www.vagrantbox.es/

比如我這裡使用:

Ubuntu 14.10(https://github.com/kraksoft/vagrant-box-ubuntu/releases/download/14.10/ubuntu-14.10-amd64.box

# vagrant box add ubuntu1404 file:///opt/boxes/ubuntu-14.10-amd64.box
# vagrant init ubuntu1404 
# vagrant up

登入到虛擬機器

# vagrant ssh

檢視虛擬機器,停止和刪除虛擬機器

# vagrant global-status
# vagrant halt <ID>
# vagrant destroy <ID>

錯誤處理:

1.  虛擬機器啟動超時

     Timed out while waiting for the machine to boot. This means that (Vagrant::Errors::VMBootTimeout)

     檢查你的機器是否開啟了 CPU 虛擬化 VT-x/AMD-V

2.  掛載共享目錄失敗

     Vagrant was unable to mount VirtualBox shared folders. This is usually (Vagrant::Errors::VirtualBoxMountFailed)

     執行:vagrant plugin install vagrant-vbguest

3.  外掛安裝失敗

     Bundler, the underlying system Vagrant uses to install plugins,
     reported an error. The error is shown below. These errors are usually
     caused by misconfigured plugin installations or transient network
     issues. The error from Bundler is:

     conflicting dependencies fog-core (~> 1.43.0) and fog-core (= 1.45.0)
       Activated fog-core-1.45.0
       which does not match conflicting dependency (~> 1.43.0)

       Conflicting dependency chains:
         fog-core (= 1.45.0), 1.45.0 activated

       versus:
         vagrant-libvirt (> 0), 0.0.41 activated, depends on
         fog-core (~> 1.43.0)

      不要直接使用 apt install vagrant 安裝,預設版本會有依賴衝突!!!