Go配置环境

222 阅读1分钟

Go配置环境

参考视频:

www.bilibili.com/video/BV1Bh…

一、一定要先安装好Go的SDK

去搜Golang下载,等待安装,然后再在vscode下载Go插件

不然就会出现类似于下面的

Failed to find the "go" binary in either GOROOT() or PATH

二、然后再在vscode下载Go插件

三、设置代理

环境变量如下

$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct

四、Go环境变量配置完成(一定要以管理员身份运行)

image-20220806025939061

五、以管理员的身份运行vscode,不然一定按照不成功!!!

image-20220806034723197

Ctrl+Shift+P输入Go:Install/Update Tools命令

全选安装,显示如下

image-20220806033815775

六、创建demo

  1. 创建一个go.mod 项目说明文件,命令行 输入:go mod init 项目名
  2. 创建main.go 文件,敲入
package main

import "fmt"

func main() {

fmt.Println("hello world")

}
  1. go run ./helloworld.go 输出测试

    image-20220806034906749