10

It's said that Golang is the compiled language, but what does it mean by compiled? If golang application is compiled to machine code, why can't I just distribute the binary (of course on corresponding arch and platform) instead of go install stuff?

qweruiop
  • 3,156
  • 6
  • 31
  • 55

1 Answers1

18

Once you compile a binary you can distribute it onto machines with the same architecture. go install, go run, etc. is just necessary for compilation.

dethtron5000
  • 10,363
  • 1
  • 31
  • 32
  • 2
    Not just the same, but the target. I build on whatever machine I'm on and deploy on four or five different systems. – Dustin Apr 15 '14 at 01:40
  • `go install/run` is not related to compiling. – Erikw Apr 15 '14 at 07:55
  • 1
    @Erikw. `go install` *compiles* and installs, and is how you build a non-main package. `go run` *compiles* in a temp location, then executes the resulting binary. – JimB Apr 15 '14 at 10:59
  • @JimB Oh that's true. What I was thinking about is that `install` is not necessary for compilation; `go build` would suffice. Useless however since the compiled package would not be installed and thus deleted when $WORK is deleted after the completion of the command. – Erikw Apr 15 '14 at 12:02
  • 1
    One of Go's unique features is that APIs are distributed *as source code*, not as `.jar`, `.dll`, `.so` or other binary packages. This is practicable because Go compiles so fast. At a stroke, it solves portability issues very simply, without resorting to needing a virtual machine (JVM etc). The (minor) downside is that producing closed-source APIs is tricky, to say the least. – Rick-777 Apr 15 '14 at 17:36
  • @Rick-777, "distributing APIs" (for what it stands) without the source code [might be implemented some time later](https://code.google.com/p/go/issues/detail?id=2775). – kostix Apr 16 '14 at 15:07