1、在go官网下载安装包
Downloads - The Go Programming Language
下载安装后
2、配置环境变量
vim ~/.bash_profile
加入以下
export GOPATH=/Users/songgenyao/go
export GOROOT=/usr/local/go
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
source ~/.bash_profile
3、下载安装vscode mac版本
在vscode中安装以下插件:
Chinese、go 、code runner
在命令行中按照以下依赖包:
go install -v github.com/ramya-rao-a/go-outline@latest
go install -v github.com/josharian/impl@latest
go install -v github.com/fatih/gomodifytags@latest
go install -v golang.org/x/tools/gopls@latest
4、helloword
package main
import (
"fmt"
)
func main(){
fmt.Println("hello,word!")
}
运行前请保存,不然会报错 main.go:1:1: expected 'package', found 'EOF'