Cedar is a good choice for building a raised garden bed. Natural oils in the wood make it rot resistant, and a cedar bed may last up to 15 years. Cedar usually costs about twice as much as pine, but it will last up to three times longer.
Redwood and black locust timbers have been known to last up to 20 years in a garden bed, but these woods are less readily available and more expensive than cedar. Composite lumbers are rot resistant and easy to work with but expensive. Pressure-treated pine is a cheaper option, but it needs to be treated with alkaline copper quat rather than chromated copper arsenate if it is to be used for growing food.