8

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 ?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Shamsher
  • 1,761
  • 4
  • 21
  • 30

7 Answers7

36

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.

Shamsher
  • 1,761
  • 4
  • 21
  • 30
2

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
RobertMyles
  • 2,673
  • 3
  • 30
  • 45
2

i was the same problem in mac but i'm using zsh

I was able to solve the problem by editing the file ~/.zsh

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go;
export PATH=$PATH:$GOPATH/bin;
jquiceno
  • 19
  • 1
1

For Go latest version go1.13.7 and above

If you have installed Go in its default location, then you no need to set up the GOROOT path.

The default location for Unix or macOS is /usr/local/go and for Windows - c:\Go.

You can verify the path using the command go env.

Note: If you are the getting the same error "command not found", then you need to unset GOROOT.

If you want to set up Go in the preferred location, then you need to export the GOROOT path like this:

export GOROOT="/your/preferred/location"

and

export PATH="$PATH:$GOROOT/bin"

in .bashrc or .bash_profile file.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
PAC
  • 1,664
  • 1
  • 18
  • 24
0

On Windows:

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

It should work now.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
27P
  • 1,183
  • 16
  • 22
0

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

giyuu
  • 99
  • 4
0

as icza said

go build leaves the executable in the current working directory.

Maybe help add ./ to you run command.

go build
./symbol
smb
  • 1