在本地的Vagrant虚拟机中运行Go脚本。

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

Run Go scripts in local vagrant machine

问题

我想使用Vagrant运行Go脚本。
当我执行vagrant up命令并运行'go version'命令时,
我没有看到任何已安装的Go,并被告知:

程序'go'当前未安装。您可以通过输入以下命令进行安装:
sudo apt-get install golang-go

所以我安装了它,现在可以运行像fmt.Println()这样的简单脚本。

然后我的问题是...

我有一个包含大量Go代码的代码库。
并且需要在Vagrant虚拟机中运行它。

那么,运行在Vagrant虚拟机之外的脚本的最佳方法是什么?
因为当我执行'vagrant up'时,我什么都看不到,所以我不得不安装Go。

英文:

I want to run Go scripts with Vagrant.
When I do vagrant up, and run the command 'go version'
I do not see any Go installed and am told that

The program 'go' is currently not installed.  You can install it by typing:
sudo apt-get install golang-go

`
So I did install it and now it's running with simple scripts like fmt.Println()

Then my question is...

I have a repository with a lot of code in Go.
And need to run this in Virtual Machine with Vagrant.

Then what would be the best way to run the scripts that were worked on outside of Vagrant VM
because when I do vagrant up I do not see anything so I had to install Go.

答案1

得分: 2

通常情况下,你不应该使用源代码和 go run 进行部署。run 命令主要是一个方便的包装器,可以在一步中构建和执行你的二进制文件。它有很多限制。你应该编译你的代码,然后运行二进制文件。

如果部署目标是不同的操作系统/架构,可以在虚拟机中构建可执行文件,只需确保虚拟机上安装了 Go。如果你的代码没有依赖于 cgo,你还可以进行交叉编译,这可能更容易一些。

英文:

You generally don't want to deploy via source and go run. The run command is mostly just a connivence wrapper that builds and executes your binary in one step. There's a lot that it can't do. Compile your code, and run the binary.

If the deployment target is a different os/architecture, there's nothing wrong with building the executable in the VM, just make sure it's has Go. You can also cross-compile you code if you don't have any dependency on cgo, which may be easier.

huangapple
  • 本文由 发表于 2014年4月23日 05:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/23230178.html
匿名

发表评论

匿名网友

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

确定