Use right away or freeze*.
Hold back some of the oil when blending. Put the pesto in a container, cover with remaining oil, and freeze.
Pesto can also be frozen in ice cube trays, although I find it just as easy to freeze in mounds on parchment paper, and then transfer to containers.
Basil Pesto https://traditionalcookingschool.com/food-preparation/recipes/5-ways-to-preserve-your-herbs-including-easy-pesto-recipe/