Addem
Addem

Reputation: 3949

Installing Go on Linux, testing fails

I'm following the instructions at this page to try to install Go. I have downloaded the file and extracted it without issue. I opened the profile file and went to the end of the file where I inserted the indicated export line. I created all the indicated directories to make a tree structure, ran the export command from the bash shell, created the hello.go file as instructed.

Yet when I run go install github.com/user/hello I get the error

can't load package: package github.com/user/hello: cannot find package "github.com/user/hello" in any of:
/usr/local/go/src/github.com/user/hello (from $GOROOT)
/work/src/github.com/user/hello (from $GOPATH)

Upvotes: 1

Views: 392

Answers (2)

dmitryro
dmitryro

Reputation: 3516

Your GOPATH needs to be your project location, so if you have structure like

/var/www/mydir/go

so you have to export

export GOPATH=/var/www/mydir/go

to set GOROOT use your go location

which go

and if it gives you /usr/local/go/bin/go , you need o set it to /usr/local/go

export GOROOT=/usr/local/go

Also, add your go to the PATH (if not there yet):

export PATH=$PATH:/usr/local/go/bin

For future reuse add all 3 export statements to your ~/.bashrc and/or ~/.bahsrc_profile

At this point you should be able to use 'go get'

Upvotes: 4

Roland Illig
Roland Illig

Reputation: 41686

Try this:

export GOPATH=$HOME/work
cd $GOPATH
mkdir src
mv github.com src/

Go expects your source code to be in a directory called src.

Upvotes: 3

Related Questions