How to keep a Go server running

in the terminal after a code change, without having to close and reopen the the terminal for the changes to take effect ?

I know I have to recompile / rerun the program (can this be automated? ), but I also have to reopen the terminal other wise the server won’t serve.

1 Like

I use this utility to automatically reload my Go web applications

I’ve never had the issue of having to reopen my terminal. Sorry I can’t help you there.

Thanks. someone else recommended something called ‘entr’, but I couldn’t quite figure it out.

1 Like


Assuming you have a working Go environment and GOPATH/bin is in your PATH , gin is a breeze to install:

go get

Then verify that gin was installed correctly:

gin -h

I use go.mod in my Go environment. I tried the above steps and it did not install.

This seems to be more up to date and plenty of *

I have never observed that one needs to close the terminal to get a new compiled artifact running… How are you starting the program?

For most if not all my programs it is enough to just CTRL-C them.

If things went south, I sometimes need to do a kill -9 from a second terminal or an SSH session even, but that is really rare.

1 Like

Thanks. lets see if I can install it …

I start the server with ./webserver, then a code change, then stop the server with Ctrl-Z, then 'go build . && ./webserver, and it doesn’t restart.

So I close and reopen the terminal and do ./webserver, and it works.

Is Ctrl-C better and/or different from Ctrl-Z ?

You use windows, I use Linux. Ctrl-Z sends EOF there IIRC.

Windows should support Ctrl-C to actually kill the program as well.

PS: if you use Linux it Mac, then ctrl-Z will actually not stop it kill, but send the program into background. Then of course you need to get it back to foreground or kill it or its parent.

Actually I am on Ubuntu.

I just did Ctrl-C and it stopped the server and I was able to restart it without closing the terminal.


Thanks, but Ctrl-C did what I needed.

Thanks, but CTRL-C did what I what I needed.

i know some way
1、go watch
this way is used in development
supervisor is a program that developed by python,it can monitor your program
an auto deployment system


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.