Raw or roasted, shelled or unshelled, nuts such as pistachios, almonds and walnuts can last for months or even years without losing their flavor -- as long as they're properly stored. If you don't keep them in the right conditions, they can turn rancid quickly and develop an unpleasant taste, although they remain safe to eat.
Unshelled and Shelled Nuts
Unshelled nuts often last longer than their shelled counterparts. For instance, unshelled almonds can last up to twice as long as shelled ones. In other cases, the differences are slight; there's no measurable difference in shelf life between shelled and unshelled hazelnuts, for instance. Shelled nuts also take up much more space, so only leave nuts unshelled if you need to store them for a longer period.
Exposure to oxygen causes the fat content in nuts to oxidize quickly; high-fat nuts such as almonds are especially vulnerable to this. Shelled nuts also absorb flavors and odors from other foods if they come into contact with them. To prevent these problems, store nuts in an airtight container such as a heavy plastic freezer bag or a covered glass or plastic bowl. Moisture hastens spoiling, so be sure that the container is clean and dry before packing the nuts. If you're going to chop the nuts, don't do so until you're ready to use them; the more of the nut's surface area that is exposed to air, the faster it spoils.
It isn't just air and moisture that can hasten spoiling -- heat and light speed up the reactions that turn nuts rancid. Store nuts in a cool, dark place. A cool pantry works for shorter periods; at room temperature, most nuts last several months. To extend the life of nuts, keep them refrigerated at 40 degrees or below. Properly refrigerated, most nuts last for about a year. Roasted nuts typically don't last as long as uncooked ones; for instance, roasted almonds spoil more quickly than unroasted ones.
The best way to keep nuts fresh for a long period is to freeze them. Stored in a freezer, most nuts last for up to 2 years. Some varieties of nut last even longer; frozen pistachios, whether shelled or unshelled, can stay good for 3 years or more, for example.