gpt4 book ai didi

ubuntu - 无法让 Golang 在 Ubuntu 中工作

转载 作者:IT老高 更新时间:2023-10-28 13:02:57 26 4
gpt4 key购买 nike

好的,所以我已经下载了 Go 1.1 并将其放入 $HOME/Documents/go 中。

然后,我将 .bashrc 修改为:

export GOPATH=$HOME/Documents/go                                                
export GOROOT=$GOPATH
export GOARCH=amd64
export GOOS=linux
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

比我获取 .bashrc 的来源,并尝试过:

jan@janpc:~$ go version
go version go1.1 linux/amd64

但我无法编译或安装任何依赖项。例如。我尝试运行我的小测试程序:

jan@janpc:~/Documents/go/src/github.com/jan/scrypt$ go run scrypt.go 
warning: GOPATH set to GOROOT (/home/jan/Documents/go) has no effect
scrypt.go:9:3: cannot find package "github.com/dchest/scrypt" in any of:
/home/jan/Documents/go/src/pkg/github.com/dchest/scrypt (from $GOROOT)
($GOPATH not set)
jan@janpc:~/Documents/go/src/github.com/jan/scrypt$

当我尝试安装依赖项时:

jan@janpc:~/Documents/go/src/github.com/jan/scrypt$ go get "github.com/dchest/scrypt"
warning: GOPATH set to GOROOT (/home/jan/Documents/go) has no effect
package github.com/dchest/scrypt: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath

它可以在 mac 上编译并正常工作。我无法弄清楚我的配置有什么问题,如果我尝试删除 $GOROOT$GOPATH 没有任何效果,而且我不知道还有什么设置它们to,而不是 Go 的路径。

编辑:我的 Mac 上没有设置 $GOROOT。但是,如果我在 ubuntu 上删除 $GOROOT,我会在尝试编译时遇到类似这样的错误。

cannot find package "fmt" in any of:
/usr/local/go/src/pkg/fmt (from $GOROOT)
/home/jan/Documents/go/src/fmt (from $GOPATH)

最佳答案

您设置的环境变量

$ export GOROOT=$GOPATH

是一个错误。任何地方都不需要也不推荐这样的设置。实际上,它削弱了 Go 构建系统所看到的环境。

删除该设置,重新创建您的环境(.bashrc)或打开一个新终端,它应该可以工作(如果不存在其他问题)。

此外,如果您不进行交叉编译,我建议您也删除这些:

export GOARCH=amd64
export GOOS=linux

简而言之,正确导出的 GOPATH 是 only 环境变量,乍一看,它是真正需要的。更多提示here .

编辑:好的,我已经下载了二进制发行版 (go1.1.linux-amd64.tar.gz)。引用自述文件:


Binary Distribution Notes

If you have just untarred a binary Go distribution, you need to set the environment variable $GOROOT to the full path of the go directory (the one containing this README). You can omit the variable if you unpack it into /usr/local/go, or if you rebuild from sources by running all.bash (see doc/install.html). You should also add the Go binary directory $GOROOT/bin to your shell's path.

For example, if you extracted the tar file into $HOME/go, you might put the following in your .profile:

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

See doc/install.html for more details.


由此可见,您一定没有正确遵循上述说明。解决这个问题,我希望它对你有用。

关于ubuntu - 无法让 Golang 在 Ubuntu 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16977703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com