I am coming at this from very much the background of the British Army so please remember that all of this may not apply to all armed forces.
The original famous red coats of the British Army date back to the New Model Army of the English Civil War period. The uniforms were dyed with what was the cheapest dye available at the time. However the red had several benefits to it a) It made it easy for commanders to see their troops on a battlefield heavily obscured by smoke from gunpowder and b) Red things are harder to count at a distance making it tricky for the enemy to estimate the numbers of soldiers they were fighting and b) It made it easy for the actual soldiers to tell friend from foe on the madness of the battlefield.
"Camouflage" began to be used when British soldiers on the Indian sub-continent in the 19th century began to stain their white summer uniforms with dust and dirt in order to stand out less on the battlefield. The term "khaki" actually means dust in Hindi, the local Indian language.
The key technological development that made the red coats less desirable was the invention of guns that did not produce large amounts of smoke when fired. This meant that the visibility on a battlefield markedly improved and battle tactics changed accordingly. Soldiers stopped fighting in serried ranks and columns and being inconspicuous so as to be less of an obvious target became more important. Again, the smokeless rifle was a development of the 19th century so before this camouflage uniforms were not needed.
Khaki (ie. Dusty or greeny brown) slowly came into universal use in the British Army over the course of the late 19th century and by WW1 all troops and officers fighting on active duty wore khaki uniforms. Camouflage patterns as we know it were developed over the 20th century as fabric technology developed and improved.