I analyze the evolution of altruistic preferences in a population where individuals are matched pairwise to play a one-shot public goods game. I determine the evolutionarily stable degree of altruism, allowing for assortative matching. The stable degree of altruism is strictly smaller than the degree of assortativity. In particular, if matching is completely random, spite is stable, and a positive degree of assortativity is necessary for pure selfishness to be stable. Furthermore, the stable degree of altruism is increasing in the degree of assortativity, and it depends on the specifics of the public goods game.