The chemical reactions and pathways involving ribitol, a pentitol derived formally by reduction of the -CHO group of either D- or L-ribose. It occurs free in some plants and is a component of riboflavin.