Can't get Golang to work in Ubuntu

前端 未结 4 2110
一个人的身影
一个人的身影 2021-02-06 23:38

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           


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 00:31

    TLDR: Unset $GOROOT by running following command in your terminal export GOROOT=""

    I had Go installed on Ubuntu 16.04 and everything was working fine.

    Then by mistake I set the $GOROOT to $GOPATH following a tutorial, at which point my build started to fail saying:

    warning: GOPATH set to GOROOT has no effect
    cannot find package "fmt" in any of:
    ... (from $GOROOT) ($GOPATH not set)
    cannot find package "io/ioutil" in any of:
    imports runtime: cannot find package "runtime" in any of:
    /home/mhsn/go/src/runtime (from $GOROOT)
    ($GOPATH not set)
    

    Every solution I read was suggesting to not set this variable, and I wanted to unset this. I found the following fix to get it unset: export GOROOT="" in bash.

    Having unset the $GOROOT back to empty which was recommended by everyone so go defaulted back to original path. And it fixed the issue for me and go build started to work again.

提交回复
热议问题