Cisco Switch config-register issues

I have a Cisco 3650 switch which doesn’t retain its startup config, and doing a sh ver shows the config-register is 0x142. I change it, reboot, and it reverts back. Took forever to find the solution, but here it is:

config t
no system ignore startupconfig switch all
config-register 0x2102
write mem
reload