In ye olden times, green often meant the sign of a Consular--a Jedi diplomat--while blue meant a Guardian--a Jedi combatant--and yellow the sign of a Sentinel--a Jedi investigator.
Jedi typically preferred uniformity in their lightsabers to signify their lack of attachments to any given things. Sith, on the other hand, preferred the red lightsaber color due to its blood-like significance, which also led Jedi to typically stay away from the color red for their own sabers.
After the Jedi purge, when Jedi had to make do with what they could get their hands on, lightsaber colors were simply a reflection of what crystal the Jedi could gather to place in their lightsaber.
In out-of-universe context, originally it was just to be the red and blue lightsabers, but when filming Return of the Jedi, it was decided that the blue of Luke's lightsaber was not as striking when placed against the blue-sky background of the desert, so they re-colored it green so it would visibly appear better. Then, when filming Attack of the Clones, Samuel L. Jackson specifically requested a purple lightsaber, as it was his favorite color and he wanted to stand out in a crowd scene.