Typically you need to make sure the lens is compatible with the camera, i.e. check the lens compatibility charts for your camera, then make sure the respective firmwares are updated so older issues are resolved.
After that, each lens has a manufacturer’s profile which will be embedded into the raw file meta data for the images captured using that lens. From there, it is up to the raw conversion software to apply the lens correction to the image. Different converters do that differently, some automatically, some only if a setting is turned on.
For in-camera jpegs, the on-board converter does the corrections automatically, assuming the camera recognizes the lens, it applies a generic profile otherwise. I do not know if that can be turned off or not.