cannot find package "fmt" in any of: 在Mac下的解决方案

背景说明:Mac安装golang,是通过brew进行安装的,因此,本文提出的解决方案并非适用所有情况。故事先声明!

一、通过brew安装golang

  • 首先查看golang的可用版本有哪些
➜  ~ brew search go
==> Formulae
algol68g                     go                           gocr                         google-authenticator-libpam  gosu                         lgogdownloader               percona-server-mongodb
anycable-go                  go-bindata                   gocryptfs                    google-benchmark             gotags                       libgosu                      protoc-gen-go
arangodb                     go-jira                      godep                        google-java-format           goto                         mongo-c-driver               pygobject
argon2                       go-statik                    goenv                        google-sparsehash            gource                       mongo-cxx-driver             pygobject3
bogofilter                   [email protected]                      gofabric8                    google-sql-tool              govendor                     mongo-orchestration          ringojs
cargo-completion             [email protected]                       goffice                      googler                      gowsdl                       mongodb                      spaceinvaders-go
certigo                      [email protected]                       golang-migrate               goolabs                      gox                          [email protected]                  spigot
cgoban                       [email protected] ✔                     gollum                       goose                        gst-plugins-good             [email protected]                  svgo
clingo                       goaccess                     golo                         gopass                       gx-go                        [email protected]                  wego
django-completion            goad                         gom                          gor                          hugo                         [email protected]                  wireguard-go
forego                       gobby                        gomplate                     goreleaser                   jfrog-cli-go                 mongoose                     write-good
fuego                        gobject-introspection        goocanvas                    goreman                      jpegoptim                    pango
gnu-go                       gobuster                     goofys                       gost                         lego                         pangomm
  • 使用brew安装最新版本的go

我们发现最新版本是1.9

➜ brew install [email protected]
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
protoc-gen-go                                                                                         step
==> Updated Formulae
node ✔            bettercap         clojure           dnsviz            ghc               helmfile          juju              [email protected]      nkf               solr              ungit
ansible-lint      bitrise           confluent-oss     dosbox-x          gnupg             influxdb          lammps            miniserve         overmind          sound-touch       valabind
bazel             chronograf        davmail           fd                groovy            istioctl          libxslt           newsboat          plantuml          swiftformat       vim
==> Renamed Formulae
todolist -> ultralist

==> Downloading https://homebrew.bintray.com/bottles/[email protected]
######################################################################## 100.0%
==> Pouring [email protected]
==> Caveats
[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

==> Summary
?  /usr/local/Cellar/[email protected]/1.9.7: 7,668 files, 294.2MB

二、配置golang环境变量

➜  vim ~/.zshrc

  将以下3个配置项追加到 .zshrc 文件,然后执行 source ~/.zshrc 即可

# GoLang
export GOROOT=/usr/local/Cellar/[email protected]/1.9.7/libexec
export GOPATH=$HOME/code/golang/projects
export PATH=$PATH:$GOROOT/bin

  其中,GOROOT 是brew安装go的路径。GOPATH是go程序的代码存放路径。

  接着,测试配置是否已生效。

  在任意路径执行 go env ,若出现以下内容,表明环境变量配置成功!

➜ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bw-pc/code/golang/projects"
GORACE=""
GOROOT="/usr/local/opt/[email protected]"
GOTOOLDIR="/usr/local/opt/[email protected]/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

 

你可能感兴趣的:(GoLang)