Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run Go binary files?

Tags:

go

I read a lot about "You can run a Go program from binaries without even having Go installed on your machine", etc. How exactly should I execute the app?

In my case I have a console application which sends emails if a certain event occurs. There also is a .toml file for configuring it. How should I run the app on a PC which does not have Go installed and is running Ubuntu 14.04.1 (Trusty Tahr) 64-bit OS?

like image 614
Yordan Yordanov Avatar asked May 30 '17 13:05

Yordan Yordanov


2 Answers

The application should be executed just like any other binary can be executed in the given OS. In your case, running on Ubuntu, you must first compile the application for that particular architecture:

env GOOS=linux GOARCH=arm go build

Then you can modify the permissions of the binary to be executable:

chmod +x my-app

And simply execute it:

./my-app
like image 54
Daniel Ribeiro Avatar answered Oct 03 '22 01:10

Daniel Ribeiro


To avoid using ./ or any other path to the binary, you can copy the binary file to your /usr/local/bin/ path.

For example-

  1. Download a binary file that was compiled with Go, for example app
  2. Provide execution permission - chmod +x ~/Downloads/app
  3. Copy binary file to /usr/local/bin - cp ~/Downloads/app /usr/local/bin/app
  4. Execute the application from anywhere - app
like image 24
Meir Gabay Avatar answered Oct 03 '22 01:10

Meir Gabay