donglao9606 2014-02-01 14:35
浏览 1360
已采纳

无法在Mac OSX上设置$ 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

enter image description here

Contents of github.com/#GITHUB_USERNAME#/smitego/smitego.go:

package smitego

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

  • 写回答

7条回答 默认 最新

  • dongliao9233 2014-02-02 01:46
    关注

    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.

    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.


    For the shell: (the manual method)

    ~/.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).

    For Sublime Text:

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

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

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况