无法让Golang在Ubuntu中工作 [英] Can't get Golang to work in Ubuntu
问题描述
好的,所以我已经下载了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版本
go版本go1.1 linux / amd64
但我无法得到它来编译或安装任何依赖项。
例如。我尝试运行我的小测试程序:
jan @ janpc:〜/ Documents / go / src / github.com / jan / scrypt $ go run scrypt.go
警告:GOPATH设置为GOROOT(/ home / jan / Documents / go)没有效果
scrypt.go:9:3:找不到软件包github.com / dchest / scrypt:
/home/jan/Documents/go/src/pkg/github.com/dchest/scrypt(from $ GOROOT)
($ GOPATH未设置)
jan @ janpc:〜/ Documents / go / src / github.com / jan / scrypt
当我尝试安装依赖项时:
jan @ janpc:〜/ Documents / go / src / github.com / jan / scrypt $ go获取github.com/dchest/scrypt
警告:GOPATH设置为GOROOT(/ home / jan / Documents / go)无效
包github.com/dchest/scrypt:无法下载,$ GOPATH不得设置为$ GOROOT。有关更多详细信息,请参阅:go help gopath
它在Mac上编译并正常工作。我想不出什么毛病我的配置,如果我尝试删除 $ GOROOT
或 $ GOPATH
什么作品,我不知道还有什么将它们设置为,以外的其他路径进入
编辑:
没有$ GOROOT上设置我的苹果电脑。但是如果我在ubuntu上删除 $ GOROOT
,当我尝试编译时,会遇到类似这样的错误。
<$ p
/ usr / local / go / src / pkg / fmt(from $ GOROOT)
/ home / jan / Documents $ p $
无法找到软件包fmt / go / src / fmt(from $ GOPATH)
您设置的环境变量
$ export GOROOT = $ GOPATH
是一个错误。没有这样的设置要求或建议。实际上,它会削弱Go构建系统所看到的环境。
删除该设置,重新创建您的环境( .bashrc
)或打开一个新的终端,它应该工作(如果没有其他问题存在)。
另外,如果你不交叉编译,我建议删除这些:
出口GOARCH = amd64
出口GOOS = linux
简而言之,正确导出的GOPATH是真正需要的 only 环境变量。一些更多的提示这里
编辑:好的,所以我下载了二进制发行版(go1.1.linux-amd64.tar.gz)。从自述文引用:
二元分布备注
如果您刚刚解散了二进制Go分发版,则需要将
环境变量$ GOROOT设置为go
目录(包含此README的目录)的完整路径。如果将它解压缩到/ usr / local / go中,或者通过运行all.bash(请参阅doc / install.html)从源重新生成
,则可以省略
变量。
您还应该将Go二进制目录$ GOROOT / bin
添加到shell的路径中。例如,如果您将tar文件解压缩到$ HOME /去,你可能
将在.profile如下:
块引用>
export GOROOT = $ HOME / go
export PATH = $ PATH:$ GOROOT / bin
有关更多详细信息,请参阅doc / install.html。
<从这一点来看,很明显,你必须没有遵循上述说明。解决这个问题,我希望它能为你工作。Ok, So I've downloaded Go 1.1 and put it into $HOME/Documents/go.
Then, I've modified my
.bashrc
to be:export GOPATH=$HOME/Documents/go export GOROOT=$GOPATH export GOARCH=amd64 export GOOS=linux export GOBIN=$GOPATH/bin export PATH=$PATH:$GOBIN
Than I've sourced the
.bashrc
, and tried:jan@janpc:~$ go version go version go1.1 linux/amd64
But I can't get it to compile or install any dependencies. Eg. I try to run my little test program:
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$
And when I try to install dependencies:
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
It compiles and works fine on mac. I can't figure out whats wrong with my config, if I try to remove
$GOROOT
or$GOPATH
nothing works, and I don't know what else to set them to, other than the path to Go.EDIT: There is no $GOROOT set on my mac. But if I remove
$GOROOT
on ubuntu, I get bunch of errors like these when I try to compile.cannot find package "fmt" in any of: /usr/local/go/src/pkg/fmt (from $GOROOT) /home/jan/Documents/go/src/fmt (from $GOPATH)
解决方案Your enviroment variable you've set by
$ export GOROOT=$GOPATH
is a mistake. Nowhere is such setting required nor recommended. Actually, it cripples the environment seen by the Go build system.
Remove that setting, recreate your environment (
. bashrc
) or open a new terminal and it should work (if no other problems exists).Additionally, if you're not cross compiling, I recommend to remove also these:
export GOARCH=amd64 export GOOS=linux
In short, proper exported GOPATH is the only environment variable which is, in the first approximation, really needed. Some more hints here.
EDIT: Okay, so I've downloaded the binary distribution (go1.1.linux-amd64.tar.gz). Quoting from README:
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.
From this it's clear that you must have not followed properly the above instructions. Fix that and I hope it will work for you then.
这篇关于无法让Golang在Ubuntu中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!