doumao9363 2013-06-07 06:33
浏览 102
已采纳

无法让Golang在Ubuntu中工作

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)
  • 写回答

4条回答 默认 最新

  • doz22551 2013-06-07 06:38
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺