Deploy Go Application in ubuntu

golang has faciltity of cross compilation. So you can write a your application on any of supported  platform and deploy it over any supported platform. So will go step by step from compilation to deployment of the project over ubuntu server ( linux server )


1. Linux Server

I mostly use ubuntu but this also work with CentOs

2. FTP/sFTP Upload Tool 

For windows I will recommand winScp Download
For Mac I personlly use ftp uploader provided by the mozzila as firefox addon Download

3. SSH Tool

For windows i will recommand putty  Download
For Mac I personally use FireSSH  Download

Thats it.

Compile the project for the linux

(I am using the windows for this tutorial , but for mac the links are show where neccessary)

Run this command to compile the project

Set GOOS for cross Compilation (windows )

> set GOOS=linux 

upper command will set the golang host architecture to linux
( this is temporary change so after reboot it will set the original host. GOOS defines the platform/ architactre for which the code will build)

> go build
This is the normal build command you use to generate the build of application
( you can also use the go install command. in that case your binary will generate in the bin folder, but for cross complation build command is recommaned by the golang team)

Upload the necessary files using the FTP/sFTP tool 

Here nessarry files means the assets files and the binary of your project
Upload files using the winscp

Use SSH client 

replace add with your binary name

$ chmod u+x app 

Running the application in background 
Run the application using SSH client
$ ./app
(here one problem is that as soon as you close your ssh client application will be terminated so use the step show below )

To make application running in background and make sure that it will not killed by hup run this command
$./app & > nohup.out

Hope you find it helpfull