How can I run Go binary files?

huangapple go评论69阅读模式
英文:

How can I run Go binary files?

问题

我读了很多关于“您可以在没有安装Go的情况下从二进制文件运行Go程序”的内容。我应该如何执行该应用程序?

在我的情况下,我有一个控制台应用程序,如果发生某个特定事件,它会发送电子邮件。还有一个.toml文件用于配置它。我应该如何在没有安装Go并且运行Ubuntu 14.04.1(Trusty Tahr)64位操作系统的计算机上运行该应用程序?

英文:

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?

答案1

得分: 30

应用程序应该像在给定的操作系统中执行任何其他二进制文件一样执行。在你的情况下,运行在Ubuntu上,你首先必须为该特定架构编译应用程序:

env GOOS=linux GOARCH=arm go build

然后你可以修改二进制文件的权限为可执行:

chmod +x my-app

然后简单地执行它:

./my-app
英文:

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

答案2

得分: 10

为了避免使用./或其他路径来执行二进制文件,你可以将二进制文件复制到/usr/local/bin/路径下。

例如:

  1. 下载一个使用Go编译的二进制文件,比如app
  2. 授予执行权限 - chmod +x ~/Downloads/app
  3. 将二进制文件复制到/usr/local/bin - cp ~/Downloads/app /usr/local/bin/app
  4. 从任何位置执行该应用程序 - app
英文:

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

huangapple
  • 本文由 发表于 2017年5月30日 21:19:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/44263450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定