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 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥15 第一个已完成,求第二个做法
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?