Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "cannot download, $GOPATH not set."

Tags:

go

Setup:

Have a look at my configuration:

$ echo $GOPATH && ls -r $GOPATH /home/cyrus/.go src  pkg  bin  $ echo $GOROOT && ls $GOROOT /usr/local/go api  AUTHORS  bin  CONTRIBUTORS  doc  favicon.ico  include  lib  LICENSE  misc  PATENTS  pkg  README  robots.txt  src  test  VERSION 

You can see that I've set a path for $GOPATH. In addition, I've created subdirectories that I may not need.

Question:

Why does the following command generate this error message?

$ go get code.google.com/p/go-tour/gotour                                                                                                                package code.google.com/p/go-tour/gotour: cannot download, $GOPATH not set. For more details see: go help gopath 
like image 958
Jürgen Paul Avatar asked Jul 26 '13 03:07

Jürgen Paul


2 Answers

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 
like image 115
icktoofay Avatar answered Oct 03 '22 00:10

icktoofay


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.

like image 45
Kyle Avatar answered Oct 03 '22 02:10

Kyle