Is the 'Getting Started' doc wrong?

https://golang.org/doc/install

In the section Test your installation

If you follow the instructions (I omitted the github part, not sure if that matters) you just end up with an error message

go install: no install location for .go files listed on command line (GOBIN not set)

This is my variation

export GOPATH=$HOME/Development/golang
cd $GOPATH
mkdir -p src/hello
vim src/hello/hello.go
go install src/hello/hello.go

go install: no install location for .go files listed on command line (GOBIN not set)

I looks like other users are having similar problems.

If I run it like
GOBIN=pwd/bin go install src/hello/hello.go

All is fine

Are the docs wrong, incomplete or am I doing something wrong myself?

Hey kswope,

If you cd into src/hello then run: go install hello

does that work for you? I believe it will work from anywhere in the file system. It should just be looking for the relative path from your go src directory.

Omit the file name. go install installs packages by default. So

go install src/hello

is sufficient. Calling go install on a single file is perhaps not officially supported and thus not mentioned in the Go docs. (Just a guess.)

If you want to compile a single .go file, try either setting GOBIN or simply run

go build hello.go

in the hello directory and you’ll get a binary in the same directory.

So the install doc is just wrong?

No, the doc is correct. It states that you should be running the following: go install github.com/user/hello

This is based on the step where it mentioned creating the directory structure “src/github.com/user/hello”. It looks for the package location starting from “$GOPATH/src”.

Your GOPATH is set to “$HOME/Development/golang”, then within the directory “golang” you should have three more directories: src, bin, pkg

When you type in go install src/hello/hello.go, you’re telling it to look in $GOPATH/src/src/hello/hello.go. So the first issue is that is will have src in the path it’s looking for twice, which won’t work since that path doesn’t exist. The second issue is that you only need to type in the package name (“hello”) and not the source code’s file name. Go will compile the files inside for you. If you want to build using filenames, you can cd into the directory holding your ‘.go’ files to use go build, and as christophberger mentioned, it will compile it and drop it in that same directory.

Hope that all made sense. Also, You may want to stick with using the suggested directory structure of $GOPATH/src/github.com/github_username. It will make things easier to manage down the road.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.