安装Go语言
将Vagrant的box添加进去。
vagrant box add https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box --name centos7
vagrant init
vi Vagrantfile
本地的目录
/Users/test/workspace/golang
虚拟机的目录
/home/vagrant/golang
Vagrant.configure(2) do |config|
config.vm.define "host" do |node|
node.vm.box = "centos7"
node.vm.hostname = "golang"
node.vm.network :private_network, ip: "192.168.43.55"
node.vm.synced_folder "/Users/test/workspace/golang", "/home/vagrant/golang", mount_options: ['dmode=777','fmode=777']
end
end
vagrant up
vagrant ssh
在虚拟机上,密码是vagrant。
sudo yum instlall golang
你好,世界。
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
如何操控
go run hello.go
或者
go build hello.go
./hello
当您想要在浏览器中尝试Go语言时,请访问https://play.golang.org/
Go语言文档
https://golang.org/doc/