英文:
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/
路径下。
例如:
- 下载一个使用Go编译的二进制文件,比如
app
。 - 授予执行权限 -
chmod +x ~/Downloads/app
。 - 将二进制文件复制到
/usr/local/bin
-cp ~/Downloads/app /usr/local/bin/app
。 - 从任何位置执行该应用程序 -
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-
- Download a binary file that was compiled with Go, for example
app
- Provide execution permission -
chmod +x ~/Downloads/app
- Copy binary file to
/usr/local/bin
-cp ~/Downloads/app /usr/local/bin/app
- Execute the application from anywhere -
app
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论