In general, an unopened jar of store-bought pesto can last for several months, typically around 6 to 8 months, if stored in a cool, dry place such as a pantry. Homemade pesto may have a shorter shelf life, usually around 3 to 5 days in the refrigerator. Once opened, pesto should be stored in the refrigerator and consumed within a few days, typically around 5 to 7 days. It's important to keep the pesto in an airtight container and to check for signs of spoilage, such as mold or a sour smell, before consuming.