The National Center for Home Food Preservation does not recommend canning homemade pesto. Doing so is potentially harmful because it supports the growth of the bacteria Clostridium botulinum. Preserve homemade pesto either in the refrigerator or in the freezer; do not preserve by canning.
It is the combination of herbs and oil together that can contribute to the growth of Clostridium botulinum, which is the bacteria that causes botulism. This applies to pesto, as it is traditionally made with fresh basil and olive oil. Preserve homemade pesto by storing in an air-tight container in the refrigerator for up to three days. It can also be kept in the freezer for long-term storage.
To preserve frozen or refrigerated pesto, wash and dry the herbs well as to avoid the growth of bacteria. Once the ingredients are blended, transfer the mixture into a clean glass or plastic jar, or a freezer bag. A thin layer of olive oil should rest at the very top. Homemade pesto can last up to a year in the freezer if this thin layer of oil is maintained.
Pesto keeps well because the olive oil acts as a natural preservative. If stored properly, the pesto retains a fresh, natural taste.