If I make an apple (or fruit) puree at home, the internet says I have to refrigerate it and then only have a couple of days to feed it to my child. But I can go buy a jar of Gerber baby puree off the shelf at the store and have it sit in my pantry for ages (only refrigerating it if I open it)? Is there anything I can do to my homemade baby food to be able to store it in my pantry for weeks?
Shelf-stable wet foods in cans, jars, plastic pouches, and the like are generally sterilized by heating them under pressure, to the point where literally every microorganism that might be inside dies. The containers need to remain sealed to maintain the sterility -- verifying the seal is the purpose of the little "pops up" button on the top of jars which are processed this way (the processing leads to low pressure inside the jar, so a popped-up button indicates that the seal has been broken.)
If you have a pressure canner, it's entirely possible to make and can (well, jar) your own baby food. There's a variety of online resources describing how to do this. (I advise ignoring any which aren't on a domain ending in .edu or .gov; this is not something you want to follow amateur youtube advice on.) Note in particular that it is not possible to safely can baby food using just boiling water; you need special equipment.