I have some doubts, I am developing a go web program on ubuntu, but my server is centos7
When the development is completed, I need to publish it to my centos server. Can I package it directly on ubuntu, and then upload the executable file to the server to run, or do I need to upload the source code to the server, and then run it after installing golang on the server
This is a question I'm having on how to publish a go web program to a server, so no code, sorry
CodePudding user response:
Yes; you can probably compile the application on your Ubuntu box and just copy the executable to the Centos server. There is no need to install Go on the server.
I say probably because this assumes that the two machines have the same architecture/processor (e.g. amd64
). If that is not the case then you can still compile on one machine and copy to another but you need to set GOARCH
before building the app. In fact you can go a step further and build the app on a Windows box (with GOOS
set to linux
) if you so desire.
I'm also assuming that your web server does not do anything particularly unusual (i.e. CGO or system calls) because that might cause an issue. The is not the case for the vast majority of applications which will run just fine (I compile an app under windows and then deploy directly onto a RUT955 with a MIPS CPU running OpenWRT linux).
One additional factor that may complicate this is resources (html
, js
, css
etc); you can embed all of these into the executable if you want.