Go Install & $PATH (MacOS

Hello, I am new to Go and not exactly proficient in other languages, but I can work my way through some issues. I’m hoping this is simple, I just can’t seem to solve it…

I was following the Go Intro codes and came to the Compile and install the application page. I was able to run $ go build my hello.go file and run it as $ ./hello. When I ran the
$ export PATH=$PATH:/path/to/your/install/directory and then the $ go install, I was getting

-bash: hello: command not found

My export path was $ export PATH=$PATH:/Users/*ComputerName*/go/bin/hello, and when I $ echo PATH… what a mess that shows.

Could someone help give me an idea of what to try? Thank you,

Hi @Box-O-Rocks, welcome to the forum.

This sounds much like Go expecting a different path here.


go env GOBIN

and compare this with the path you have added to $PATH.

In case go env GOBIN is empty, run

go env GOPATH

which returns the parent directory of Go’s local pkg and bin directories.

Tip: you can change GOBIN to point to a directory of your liking by calling

go env -w GOBIN=/your/path/to/custom/gobin

(But I would first try the other way round and match the $PATH to the current GOBIN.)

1 Like

The PATH variable shall point to the folder containing the binary, not to the binary itself.

Also when you say echo $PATH shows a mess, please tell us what the mess is. It might still be expected.

1 Like

When I $ echo $PATH it returns this…


Preformed your suggestion. No joy.

-bash: hello: command not found

According to the Go instructions I should be able to run $ hello and have it return

map[Darrin:Hail, Darrin! Well met! Gladys:Hi, Gladys. Welcome! Samantha:Hail, Samantha! Well met!]

Not sure why, but that PATH is not a mess, it’s just not showing the entry you wanted to add.

How and where did you add the export?

$ export PATH=$PATH:/Users/ComputerName/go/bin/hello

The instructions were to run $ export PATH=$PATH:/path/to/your/install/directory

What’s the output of your go env GOBIN?

Edited to add: Did you try @NobbZ’s advice and change the path to point to the bin dir rather than to the hello binary?

That only affects the current shell, not any other you open.


And did you add this path to $PATH?

1 Like

So that is what you should add to PATH, the most portable way to add the correct thing is:

export PATH=${PATH}:$(go env GOBIN)
1 Like

So following the instructions from, i create the dir “hello” and the file “hello.go”. By my understanding, I am asking it was supposed to point to the directory “hello”… ?

I updated my original post to read a little easier.

Following the instructions from Go, are you suggesting i should run your command instead of their instructions? The link to the instructions is in the original post.

go install should copy the binary to the GOBIN.

So make sure that the GOBIN is in PATH, the most portable way is how I showed above.

Please remember, that it works only for the current shell, and has to be repeated for each shell you open unless you add an equivalent line to your shells init files.

Thank you.

The GOBIN is in the ../bin while the PATH is in ../bin/hello

After using my command, it should not be as you describe.

Instead the final entry in the PATH should be exactly the same as the GOBIN.

Also you might need to remove the hello folder from the GOBIN, as it’s in the way when go install tries to copy the hello binary.

That fixed it… or at least that made it operate as the instructions intended. Thank you very much.

Do you think if I would have ran $ export PATH=$PATH:/Users/*ComputerName*/go/bin without ../hello that I wouldn’t have had the problem?

This is exactly what my command would expand to. So yes, using this wouldn’t have caused any issues from the beginning

I knew it was something small. Thank you again for the help.