The normal way to do so is to sell your game through a DRM enabled platform like Steam.
Alternatively, you could also host a server that authenticates license keys, but those are generally easily bypassed as well.
Edit: It is also very common to have your game free to begin with, but unlock additional content through DLC or IAP.