Hair color is determined by the amount and type of melanin present in the hair shaft. The two main types of melanin are eumelanin (which produces brown and black pigments) and pheomelanin (which produces red and yellow pigments). Different combinations of these pigments result in the variety of natural hair colors we see, like blonde, brown, red, and black.
Purple hair requires a pigment that doesn't exist naturally in humans. To get purple hair, you would need to artificially dye it.