不能让Golang在Ubuntu工作

前端之家收集整理的这篇文章主要介绍了不能让Golang在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 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没有任何作用,我不知道还要设置什么,除了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是唯一的环境变量,它在第一次近似中是真正需要的.更多的提示here.

编辑:好的,所以我已经下载了二进制分发(go1.1.linux-amd64.tar.gz).从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.

从这一点,很明显你必须没有正确遵循上述说明.解决这个问题,希望对你有帮助.

原文链接:https://www.f2er.com/go/187000.html

猜你在找的Go相关文章