macOS下Go语言开发环境的搭建
https://www.jianshu.com/p/29124e2f656e
https://blog.csdn.net/lovechris00/article/details/71178881
1.下载安装 Go语言
下载地址:https://golang.google.cn/dl/
![](http://upload-images.jianshu.io/upload_images/14706184-c84e38c11a84ead9.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
image.png
下载完成后,直接双击 文件进行安装
![](http://upload-images.jianshu.io/upload_images/14706184-6a2bf726aa3f11c1.png?imageMogr2/auto-orient/strip|imageView2/2/w/932/format/webp)
image.png
一路点击next即可
![](http://upload-images.jianshu.io/upload_images/14706184-52e9617d7e38d623.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
image.png
最后在终端执行 go version 命令,如过能获取到版本信息则说明安装成功了
![](http://upload-images.jianshu.io/upload_images/14706184-005ac86d4e67a4b6.png?imageMogr2/auto-orient/strip|imageView2/2/w/788/format/webp)
2.配置环境变量
在终端输入go env会打印出go 相关的所有环境变量。
![](http://upload-images.jianshu.io/upload_images/14706184-ce525ef65cfa0957.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
这些环境变量,仅设置下面这两个就足够了
一个是GO111MODULE 设置为 on,表示使用 go modules 模式
$ go env -w GO111MODULE=on
一个是开启代理,防止下载包失败(前面可能你已经设置过)
$ go env -w GOPROXY=https://goproxy.cn,direct
3. 配置 Goland 环境
学习编程语言,使用一个称心的 IDE,可以省去很多麻烦。
因为已经习惯了 JetBrains 风格的IDE,所以这里我使用 JetBrains 专门为 Go语言开发的IDE:。
当你的可以正常使用 Goland 后,通过点击设置进入如下界面,创建我的项目目录,顺便设置好 GOROOT 。
![](http://upload-images.jianshu.io/upload_images/14706184-b09e19af2053e550.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
创建好Project后,再点击 Files->Settings->GOPATH,添加我们的项目目录
![](http://upload-images.jianshu.io/upload_images/14706184-4504c1184240572b.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
新建一个文件夹src,用于存放源文件,在src目录下创建hello.go文件,点击运行按钮,我们看到了熟悉的 Hello, World!
![](http://upload-images.jianshu.io/upload_images/14706184-0c03c11fdd13cb65.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
![](http://upload-images.jianshu.io/upload_images/14706184-d6d2c18049df7459.png?imageMogr2/auto-orient/strip|imageView2/2/w/800/format/webp)
作者:老朱别问
链接:https://www.jianshu.com/p/29124e2f656e
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。