1. 从官网下载安装包安装

2. 配置国内镜像

  1. # Mac 环境
  2. # 编辑 vi ~/.bash_profile,新增如下
  3. # go start
  4. go env -w GO111MODULE=on
  5. go env -w GOPROXY=https://goproxy.io,direct
  6. export GOROOT=/usr/local/go
  7. export PATH=${PATH}:/Users/用户名/go/bin
  8. # go end
  9. # source ~/.bash_profile

小提示:在mac环境配置中,${PATH}:xxx 相当于xxx:$PATH,类似代码语法 PATH += xxx;$PATH 与${PATH}等同,如我的.bash_profile文件如下

  1. export PATH=/Users/apple/development/flutter/bin:$PATH
  2. export ANDROID_HOME="/Users/apple/Library/Android/sdk"
  3. export PATH=${PATH}:${ANDROID_HOME}/tools
  4. export PATH=${PATH}:${ANDROID_HOME}/platform-tools
  5. export PUB_HOSTED_URL=https://pub.flutter-io.cn
  6. export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  7. export PATH="$PATH:`yarn global bin`"
  8. # go start
  9. go env -w GO111MODULE=on
  10. go env -w GOPROXY=https://goproxy.io,direct
  11. export GOROOT=/usr/local/go
  12. export PATH=${PATH}:/Users/apple/go/bin
  13. # go end

3. vscode 安装开发依赖

  • command+shift+p 选中go:install/update tools
  • 选中全部,点击确定后开始安装