dpylt7626401 2014-07-16 10:32
浏览 1611
已采纳

Go:设置GOPATH时,出现$ GOPATH错误

When running the go get command :

sudo go get github.com/go-sql-driver/mysql

I get the following error

package github.com/go-sql-driver/mysql: cannot download, $GOPATH not set. For more details see: go help gopath

However $GOPATH is already set.

Running echo $GOPATH gives /Users/userxyz/Desktop/Code

Running go env gives

.....

GOPATH="/Users/userxyz/Desktop/Code"

...

GOROOT="/usr/local/go"

.....

I have already tried setting GOPATH as an environment variable by adding the following lines

export GOPATH="$HOME/Desktop/Code"
export PATH=$PATH:$GOPATH/bin

to the following files, alternatively

~/.profile (/etc/profile)
~/.bashrc
~/.bash_profile
  • 写回答

5条回答 默认 最新

  • duanqiu2064 2014-07-16 10:36
    关注
    sudo go get github.com/go-sql-driver/mysql
    

    This runs go get under root user, which does not have $GOPATH set.

    Just do:

    go get github.com/go-sql-driver/mysql
    

    Generally, do:

    go get
    

    in the project folder, and it will install all dependencies. The following will install dependencies mentioned in tests:

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

报告相同问题?

悬赏问题

  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信