Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command not found after go build

Tags:

go

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 ?

like image 927
Shamsher Avatar asked Oct 02 '16 11:10

Shamsher


3 Answers

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.

like image 128
Shamsher Avatar answered Oct 17 '22 06:10

Shamsher


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
like image 23
RobertMyles Avatar answered Oct 17 '22 07:10

RobertMyles


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.

like image 1
PAC Avatar answered Oct 17 '22 07:10

PAC