To prevent egg yolks in hard-boiled eggs from turning green you need to be cautious not to overcook the eggs. Once eggs overcook they will start to turn green and the whites will even turn brown after cooking too long.