Go命令报错 cannot load Bufio

环境

  • 操作系统: macOS 10.14.6 / 18.7.0 Darwin Kernel Version
  • golang版本: 1.13.15 (采用homebrew安装)

问题描述

写了一个打印出hello world的go文件 在使用go run hello.go

执行时报错cannot load fmt: malformed module path "fmt": missing dot in first path element

$GOROOT/src目录中执行go install golang.org/x/lint/golint时报错

build golang.org/x/lint/golint: cannot load bufio: malformed module path "bufio": missing dot in first path element

解决

golang的真实安装目录是在/usr/local/Cellar/[email protected]/1.13.15, 同时brew会软链该目录到/usr/local/opt/[email protected], 之前是把$GOROOT环境变量设置成/usr/local/opt/[email protected], 也就造成了上面的问题.

解决办法是把$GOROOT环境变量设置成/usr/local/opt/[email protected]/libexec目录, 即

export GOROOT=/usr/local/opt/[email protected]/libexec
本文由 络壳 原创或整理,转载请注明出处