Error “cannot download, $GOPATH not set.”

后端 未结 6 1385
南旧
南旧 2021-02-02 08:41

Setup:

Have a look at my configuration:

$ echo $GOPATH && ls -r $GOPATH
/home/cyrus/.go
src  pkg  bin

$ echo $GOROOT &&         


        
相关标签:
6条回答
  • 2021-02-02 09:07

    My $GOROOT directory was created with owner: root and group: wheel instead having me as the owner and admin as the group. I'll guess that I used sudo when I shouldn't have (or some tool did it for me). As such go get could not write the packages to $GOROOT and hence the $GOPATH not set and permission denied errors.

    By using chown and chgrp on my $GOROOT (with -R to get subfolders) 'go get...' worked. In my case VS Code was now able to install the Go components I was after.

    0 讨论(0)
  • 2021-02-02 09:07

    First do a `go env' and check the path GOROOT. Accordingly set the GOPATH. In my case, it had to set GOPATH to /usr/lib/go. Earlier i tried it with /usr/share/go and /usr/bin/go but it didn't work.

    0 讨论(0)
  • 2021-02-02 09:08

    If you set a variable like this:

    GOPATH=$HOME/go
    

    It won't be exported to any subprocesses. It's only available to that process. If you want to export it to subprocesses, use export:

    export GOPATH
    

    You can also combine the assignment and export:

    export GOPATH=$HOME/go
    
    0 讨论(0)
  • 2021-02-02 09:09

    i had setup GOPATH and it showed correctly with command go env. i had to give the correct permissions to the go directory using chmod and install gb by go get github.com/constabulary/gb/....

    0 讨论(0)
  • 2021-02-02 09:20

    $GOPATH should be your current workspace , a folder where your project resides. or just cd ~/go and try to run those commands. Or you can just update $GOPATH in ~/.bashrc or ~/.bashrc_profile on ubuntu

    0 讨论(0)
  • 2021-02-02 09:21

    When you run go env, you should be able to see if your GOPATH has been set. On my case though, this command solves it when I had it run on my terminal.

    export GOPATH=/usr/local/bin
    
    0 讨论(0)
提交回复
热议问题