到官网 点击下载最新的virtualbox,直接安装。
到官网 下载最新的vagrant,然后安装,
一、下载一个合适的box 下载你想要的操作系统box。我下载的是centos7。
$ /d/vagrant
$ cd /d/vagrant
2. 把下载好的,移动到D盘vagrant目录下面。
3. 添加box命令:
vagrant box add {title} {url}
vagrant init {title}
vagrant up

vagrant box add 是添加box的命令
{title}可以自行设置,我这里使用的是 centos7
1. 安装box,切换目录到vagrant下。
$ cd /d/vagrant
$ vagrant box add CentOs7
Downloading or copying the box...
Extracting box...te: 47.5M/s, Estimated time remaining: --:--:--)
Successfully added box 'base' with provider 'virtualbox'!

window系统中应该是放到了: C:\Users\当前用户名.vagrant.d\boxes\目录下。
# 如果是才add 的box,就必须执行本步骤,初始化一次后,以后启动系统,就不需要执行本步骤。
$ 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 `` for more information on using Vagrant.
这样就会在当前目录生成一个 Vagrantfile的文件,里面有很多配置信息。
2. 配置信息如下:
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
 # The most common configuration options are documented and commented below.
 # For a complete reference, please see the online documentation at

 # Every Vagrant development environment requires a box. You can search for
 # boxes at = "CentOS7"

 # Disable automatic box update checking. If you disable this, then
 # boxes will only be checked for updates when the user runs
 # `vagrant box outdated`. This is not recommended.
 # config.vm.box_check_update = false

 # Create a forwarded port mapping which allows access to a specific port
 # within the machine from a port on the host machine. In the example below,
 # accessing "localhost:8080" will access port 80 on the guest machine.
 # NOTE: This will enable public access to the opened port "forwarded_port", guest: 80, host: 8080

 # Create a forwarded port mapping which allows access to a specific port
 # within the machine from a port on the host machine and only allow access
 # via to disable public access
 # "forwarded_port", guest: 80, host: 8080, host_ip: ""

 # Create a private network, which allows host-only access to the machine
 # using a specific IP. "private_network", ip: ""

 # Create a public network, which generally matched to bridged network.
 # Bridged networks make the machine appear as another physical device on
 # your network.
 # "public_network"

 # Share an additional folder to the guest VM. The first argument is
 # the path on the host to the actual folder. The second argument is
 # the path on the guest to mount the folder. And the optional third
 # argument is a set of non-required options.
 config.vm.synced_folder "/data/wwwroot/vagrant", "/data/wwwroot/vagrant"

 # Provider-specific configuration so you can fine-tune various
 # backing providers for Vagrant. These expose provider-specific options.
 # Example for VirtualBox:
 # config.vm.provider "virtualbox" do |vb|
 # # Display the VirtualBox GUI when booting the machine
 # vb.gui = true
 # # Customize the amount of memory on the VM:
 # vb.memory = "1024"
 # end
 # View the documentation for the provider you are using for more
 # information on available options.

 # Enable provisioning with a shell script. Additional provisioners such as
 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
 # documentation for more information about their specific syntax and use.
 # config.vm.provision "shell", inline: <<-SHELL
 # apt-get update
 # apt-get install -y apache2
config.vm.synced_folder "/data/wwwroot/vagrant", "/data/wwwroot/vagrant"
3. 启动系统
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'base'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
在系统中,如mac,git,可直接使用 vagrant ssh 来完成链接。
使用第三方如xshell,ip地址是:,虚拟机启动时观察映射的22端口号是多少,一般是2200 或者2222
用户名与密码均是: vagrant
命令 作用
vagrant box add 添加box的操作
vagrant init 初始化box的操作,会生成vagrant的配置文件Vagrantfile
vagrant up 启动本地环境
vagrant ssh 通过 ssh 登录本地环境所在虚拟机
vagrant halt 关闭本地环境
vagrant suspend 暂停本地环境
vagrant resume 恢复本地环境
vagrant reload 修改了 Vagrantfile 后,使之生效(相当于先 halt,再 up)
vagrant destroy 彻底移除本地环境
vagrant box list 显示当前已经添加的box列表
vagrant box remove 删除相应的box
vagrant package 打包命令,可以把当前的运行的虚拟机环境进行打包
vagrant plugin 用于安装卸载插件
vagrant status 获取当前虚拟机的状态
vagrant global-status 显示当前用户Vagrant的所有环境状态



:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: