read

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

I started with this simple hello.go

Influenced by my prior programming experinces and having skipped reading some basics. I ran

go install hello

resulted in error

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

Ok..

go install hello.go

same error

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

I followed on to verify the things that go expects ###How to organize the go folders ?

  1. Set GOPATH - this must be set to the home of all you go code
  2. Define your work space - this must be $GOPATH/src . You need not set this as a system path ; but golang expects your code be organized in this fashion . Actually go needs the following defined in the $GOPATH
  • src [where all your source go]
  • bin [this will be created and maintained by go. this is where go binaried live]
  • pkg [home for all imported packages]

3.Add $GOPATH/bin to $PATH

This is how i have organized my folders

$GOPATH
  --src
     --ganeshramr.github.com
        --go-projects
          --hello
            --hello.go

So i had all this set right, but i still got the error.I assumed something wrong with the code so i ran it

go run hello.go

And I got the expected output

I am a gopher wannabe

so nothing is wrong with the code

Then i did what i should have done to begin with .I tried to understand what go install does reading.

go help install

Install compiles and installs the packages named by the import paths,
along with their dependencies.

Couldn’t make out much , but understood install got to do something with the packages and not the individual go files

go list all helped me list all the packages i had in my system and there at the bottom of the list saw my package listed ganeshramr.github.com/go-projects/hello

Ok so go install ganeshramr.github.com/go-projects/hello Bingo!!! NO ERRORS or you can get into the package for example to $GOPATH/ganeshramr.github.com/go-projects/hello and run go install

So what you really install is your package. The successful installation can be verified by observing the package installed in $GOPATH/bin after which you can just run the program from command line as hello automagically , provided you have $GOPATH/bin in your system PATH.

Blog Logo

Ganeshram Ramamurthy


Published

Image

~bodhi~

-learning is a continous process-

Back to Overview