编译后未找到Golang命令

I have install and setup go.

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

I have created a package at following location.

$HOME/go/src/github.com/shamsher31/gosymbol

I build inside package folder using

go build

It creates binary in bin folder inside GOPATH
But when I try to run package name from command line it gives following error.

symbol: command not found

How can I execute binary from command line ?

You need following configuration for ubuntu.

$ sudo gedit ~/.bashrc

Add the following config

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go;
export PATH=$PATH:$GOPATH/bin;

/usr/local/go/bin will be your go installation path and $GOPATH/bin will be where your custom build packages will get installed.

On Windows:

1) Set $GOPATH env , e.g. $HOME/go
2) Add $GOPATH/bin into $PATH

It should work now.

I was having a similar problem on OSX, I found this the easiest way to get golang up and running:

With HomeBrew:

brew install go

Then add these to your .bash_profile:

export PATH=$PATH:$GOPATH/bin
export GOPATH=$HOME/.go

for mac

example I put custom go folder in workspace directory. you could change my custom go directory workspace by your own.

add the following script to .bashrc

export GOROOT="/usr/local/go"
export GOPATH="$HOME/workspace/go"
export PATH="$HOME/workspace/go/bin:$PATH"

then run source .bashrc on your terminal