doutao4480 2014-12-21 14:09
浏览 146
已采纳

设置GOPATH无效

On MacOS Yosemite, inside my .profile file I have set:

GOPATH="$HOME/go"
PATH="$PATH:$GOPATH/bin"

But go env outputs:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

I also created .bashrc inside my home folder, added the GOPATH variable to the file, but the end result is the same. And it seems that until I set this path variable, I'm unable to install any Go package. Any ideas what could be wrong?

  • 写回答

1条回答 默认 最新

  • dsdsds12222 2014-12-21 14:32
    关注

    You need to have export on your declaration, the reason being that when you start an application from shell your app isn't receiving your updated $PATH. When you export a variable it adds it to the list of environmentals sent to all future application invocations.

    See here for more information on the environment within a shell.

    Also, try investigating the choices between .profile and .bash_profile since if you have a similar export in your .bash_profile and you don't append to the $PATH it will overwrite your export. See this question for more info.

    .profile is shell and bash compatible where as .bash_profile is only bash compatible (if you don't know the difference, use .bash_profile).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办