Most olivine found at Earth’s surface is in dark-colored igneous rocks. It usually crystallizes in the presence of plagioclase and pyroxene to form gabbro or basalt. These types of rocks are most common at divergent plate boundaries and at hot spots within the centers of tectonic plates.

Olivine has a very high crystallization temperature compared to other minerals. That makes it one of the first minerals to crystallize from a magma. During the slow cooling of a magma, crystals of olivine may form and then settle to the bottom of the magma chamber because of their relatively high density. This concentrated accumulation of olivine can result in the formation of olivine-rich rocks such as dunite in the lower parts of a magma chamber.
Crystals of olivine are sometimes formed during the metamorphism of a dolomitic limestone or dolomite. The dolomite contributes magnesium, and silica is obtained from quartz and other impurities in the limestone. When olivine is metamorphosed, it is transformed into serpentine.
Olivine is one of the first minerals to be altered by weathering. Because it is so easily altered by weathering, olivine is not a common mineral in sedimentary rocks and is only an abundant constituent of sand or sediment when the deposit is very close to the source.