首先,下载安装包,国内可以在这上面下载https://studygolang.com/dl
目前的稳定版是go1.12.5.darwin-amd64.pkg
下载安装后,配置环境变量
vim ~/.bash_profile
在文件内最后加入
# Enable the go modules feature
export GO111MODULE="on"
# Set the GOPROXY environment variable
export GOPROXY="https://mirrors.aliyun.com/goproxy/"
GOROOT=/usr/local/go
export GOROOT
export GOPATH=/Users/liuyue/wodfan/work/mygo
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN:$GOROOT/bin
这里简单解释一下:
GOROOT: go安装目录
GOPATH:go工作目录 GOBIN:go可执行文件目录 PATH:将go可执行文件加入PATH中,使GO命令与我们编写的GO应用可以全局调用
# Enable the go modules feature
export GO111MODULE="on" # Set the GOPROXY environment variable export GOPROXY="https://mirrors.aliyun.com/goproxy/"
这两行配置是为了使用go-get命令能更加快速的用国内代理源下载需要的模块。
存盘退出后,使环境变量生效
source ~/.bash_profile
打开vscode 安装Go插件 同时也可以安装Code Runner插件,这个插件可以运行多种语言的脚本文件
重启vscode
新建test.go
package main
import "fmt"
func main() {
fmt.Println("hello go!")
}
右键 "Run Code"
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有