无法在Mac OSX上设置$ GOPATH [英] Cannot set $GOPATH on Mac OSX

查看:167
本文介绍了无法在Mac OSX上设置$ GOPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置我的 $ GOPATH 变量来运行我机器上的一些示例代码:

I'm trying to set my $GOPATH variable to run some example code on my machine:

$ smitego-example go run main.go 
main.go:5:2: cannot find package "github.com/#GITHUB_USERNAME#/smitego" in any of:
    /usr/local/go/src/pkg/github.com/#GITHUB_USERNAME#/smitego (from $GOROOT)
    ($GOPATH not set)

$ smitego-example export $GOPATH=$HOME
-bash: export: `=/Users/#OSX_USERNAME#': not a valid identifier

的内容github.com/#GITHUB_USERNAME#/smitego/smitego.go

package smitego

如何设置我的 GOPATH 所以它永远和永远工作?

How can I set my GOPATH so it works always and forever?

推荐答案

更新,从Go 1.8 :如果您安装Go 1.8(发布:2017年2月)或更高版本,则GOPATH为由Go工具链自动确定

Update, as of Go 1.8: If you're installing Go 1.8 (released: Feb 2017) or later, GOPATH is automatically determined by the Go toolchain for you.

它在macOS(nee OS X)上默认为 $ HOME / go - 例如 /用户/无光泽/去/ 。这使得开始使用Go更容易,您可以在安装Go后立即 go get< package>

It defaults to $HOME/go on macOS (nee OS X) - e.g. /Users/matt/go/. This makes getting started with Go even easier, and you can go get <package> right after installing Go.

对于shell:(手动方法)

〜/ .bash_profile应包含 export GOPATH = $ HOME / go 以及 export PATH = $ GOPATH / bin:$ PATH 。使用 $ 很重要:请务必注意我使用过的地方(以及我没有的地方)。

~/.bash_profile should contain export GOPATH=$HOME/go and also export PATH=$GOPATH/bin:$PATH. The use of the $ is important: make sure to note where I've used it (and where I have not).

对于Sublime Text:

Sublime文本菜单>首选项>程序包设置> GoSublime>设置:用户

Sublime Text menu > Preferences > Package Settings > GoSublime > Settings: User

{
        "shell": ["/bin/bash"],
        "env": {"GOPATH": "/Users/#USERNAME#/go/"},
}

确保您的 GOPATH 未设置为包的完整路径;只是您的 go 文件夹的根目录,其中 src,pkg和bin 驻留。如果您没有使用 GoSublime ,建议先安装。

Make sure your GOPATH is not set to the full path of the package; just the root of your go folder where src, pkg, and bin reside. If you're not using GoSublime, I'd suggest installing that first.

这篇关于无法在Mac OSX上设置$ GOPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆