在 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 安装,默认版本会有依赖冲突!!!