在Mac os 下配置Go lang 开发环境
source link: https://v3u.cn/a_id_88
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
在Mac os 下配置Go lang 开发环境
首先,下载安装包,国内可以在这上面下载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"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK