The general way minerals are formed is through the process of crystallization. There are many different example of this, including through the crystallization of magma or the crystallization of lava. The crystallization of magma cools inside the crust, while the crystallization of lava cools and then hardens on the surface. The process of the crystallization of materials dissolved in water is another variation of this process, as when the liquids cool, they form crystals.
Another way that minerals are formed is through the evaporation of a solution. Table salt, for example, formed over millions of years when ancient seas slowly evaporated, and this happens daily in areas like the Midwest, Southwest, and the Gulf coast.
Lastly, minerals can form from hot water solutions. Veins, narrow channels or slabs of a mineral that is different from the surrounding rock, can configure when a pure metal crystallizes from a hot water solution.