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

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

问题描述

我正在尝试做一个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

当我执行 go env 时,Go 值列表如下所示:

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"

显然没有设置 GOPATH,我应该如何设置以及在哪里设置?

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?

推荐答案

新方式:

看看这个答案.

老方法:

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

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天全站免登陆