在Homebrew cask中安装并启动VirtualBox和Vagrant直到完成
前提 tí)
• 已安装了Homebrew。
• 已安装了Homebrew cask。
• 已将安装目录更改为/Applications。
步驟
・安装VirtualBox
・安装Vagrant
・添加box
・生成vagrantfile
・启动vagrant
・SSH连接
・停止vagrant
安装Vagrant
$ brew cask install vagrant
$ brew cask install vagrant-manager
安装VirtualBox
$ brew cask install virtualbox
如果出现以下错误
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "4fb35db2-bba9-4110-9cfd-63914883615e", "--type", "headless"]
请在系统设置 > 安全画面上允许。
如果想要更改安装VirtualBox时生成的VirtualBox VMs目录的位置
默认情况下,它会被生成在用户名称目录的直接下方。
首先,打开VirtualBox应用。
在设置中,编辑默认的虚拟机文件夹。
请在安装了Box之后进行调查,因为可以在应用程序内进行操作并进行更改。
添加盒子
$ vagrant box add centos/7
将安装CentOS 7。
运行时会要求选择提供者。
由于此次使用VirtualBox,选择3。
==> box: Loading metadata for box 'centos/7'
box: URL: https://vagrantcloud.com/centos/7
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop
Enter your choice:
如果出现以下显示,则说明安装成功:
==> box: Successfully added box 'centos/7' (v1905.1) for 'virtualbox'!
Chỉnh sửa ban đầu của tệp Vagrantfile
$ vagrant init centos/7
启动vagrant
$ vagrant up
SSH连接
$ vagrant ssh
停止Vagrant
$ vagrant halt
最后
我的文件夹结构
/Users/ユーザー名/VirtualMachine
├── VirtualBox VMs
│ └── centos7_default_1569940899284_29391
│ ├── Logs
│ │ ├── VBox.log
│ │ ├── VBox.log.1
│ │ └── VBox.log.2
│ ├── centos-7-1-1.x86_64.vmdk
│ ├── centos7_default_1569940899284_29391.vbox
│ └── centos7_default_1569940899284_29391.vbox-prev
└── centos7
└── Vagrantfile
这次安装了CentOS 7并搭建了虚拟环境。
要启动虚拟环境,只需在包含Vagrantfile的目录中运行 “vagrant up” 命令即可启动。
VirtualBox VMs会在安装盒子后生成。
更改生成位置在上面进行了描述。
请参考
以下是一种可能的中文翻译:
https://www.gatch.site/entry/vagrant-virtualbox-mac#virtualbox的安装
http://www.vagrantbox.es/
https://qiita.com/sudachi808/items/3614fd90f9025973de4b
https://qiita.com/ohuron/items/057b74a42b182b200ae6