我如何在Ubuntu上设置GOPATH环境变量?我必须编辑什么文件? [英] how do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

查看:407
本文介绍了我如何在Ubuntu上设置GOPATH环境变量?我必须编辑什么文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个去获得

  go获取github.com/go-sql-driver/mysql 

并且失败,并显示以下错误:

  package github.com/go-sql-driver/mysql:无法下载,$ GOPATH未设置。有关详细信息,请参阅:go help gopath 

当我做一个 go env ,Go值列表如下所示:

  ubuntu @ ip-xxx-x-xx -x:〜$ go env 
GOARCH =amd64
GOBIN =
GOCHAR =6
GOEXE =
GOHOSTARCH =amd64
GOHOSTOS =linux
GOOS =linux
GOPATH =
GORACE =
GOROOT =/ usr / lib / go
GOTOOLDIR =/ usr / lib / go / pkg / tool / linux_amd64
CC =gcc
GOGCCFLAGS = - g -O2 -fPIC -m64 -pthread
CGO_ENABLED =1

显然没有设置GOPATH,我怎么设置它? p>

我看到很多提到这个错误的线程,但没有提供我的问题的答案,哪个文件需要被编辑以提供这个路径的值?

解决方案

只需将以下几行添加到〜/ .bashrc中,这将会持续。但是,您可以在我的示例中使用其他您喜欢的路径作为GOPATH而不是 $ HOME / go

  export GOPATH = $ HOME / go 
export PATH = $ PATH:$ GOROOT / bin:$ GOPATH / bin


I am trying to do a go get:

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

and it fails with the following error:

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

when I do a go env , a list of Go values is shown as below:

ubuntu@ip-xxx-x-xx-x:~$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"

clearly the GOPATH is not set, how and where do I set it?

I see many threads that mention this error but none that provide an answer to my question, which file needs to be edited to provide a value for this path?

解决方案

Just add the following lines to ~/.bashrc and this will persist. However, you can use other paths you like as GOPATH instead of $HOME/go in my sample.

export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

这篇关于我如何在Ubuntu上设置GOPATH环境变量?我必须编辑什么文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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