打开 .bash_profile (他是隐藏文件)
1.使用默认的路径
export GOPATH=/Users/apple/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
2.自定义文件路径
export GOROOT=/Users/你的名字/go
export GOPATH=/Users/你的工程路径
export GOBIN=$GOPATH/bin // 这个固定的
export PATH=$PATH:$GOBIN // 这个固定的
还需要在vscode setting.json balujing shezhiyixia
在终端执行 source ~/.bash_profile 或者 source .bash_profile 让路径生效
经过测试,在使用默认路径/Users/apple/go/src 下创建的工程
发现是文件夹带括号引起的 引用包出错
!!!!!
"goCode/chapter04/demo25(byy)/utils" 报错
"goCode/chapter04/demo25byy/utils" 正确
但是自定义路径依旧显示错误,还没找到解决方法
chapter04/demo25/main/main.go:6:2: cannot find package "goCode/chapter04/demo25/utils" in any of:
/usr/local/go/src/goCode/chapter04/demo25/utils (from $GOROOT)
/Users/apple/go/src/goCode/chapter04/demo25/utils (from $GOPATH)
网友评论