A warrior is a member of a class, generally it is a privilege of birth. The warrior is not a universal concept but variants of it exist world wide. The first warriors could also be called shaman-kings. Most likely they developed from hunter-gather groups that occupied mountains, jungles or dry plains. These hunter-groups, often at war with each other, were in the habit of raiding the first agricultural settlements. At some point, these settlements probably got the idea that they could offer the hunter-groups ruler-ship in exchange for protection. They thus became the first warrior classes.
These warrior shaman's most powerful weapon was inspiring fear. Chinese historians record this kind of shaman-commander charging off into battle with a poisonous snake in each hand, wild hair, animal skins, horns and a terrifying mask. After countless generations, these shaman-warriors morphed into warriors with a strict code. The warriors of neighboring kingdoms fought each other on designatied fields of battle, with codes of conduct and rules about how to kill, whom to kill, and what to do with captured enemies.
In China, this was the time when the Zhouyi was written. The Zhouyi eventual developed into the Yijing (I Ching) or the book of changes. Richard Rutt's translation and commentary sheds really interesting light on this era of warrior inspired codes that used divination and both mass animal and human sacrifice as a tools for staying in power.
This is not just history. The warrior-shaman-kings are still around in isolated parts of Indonesia. (See Don F. Draeger's beautiful book the The Weapons & Fighting Arts of Indonesia.) The Lords Army in the Congo, would also qualify. As would The Terror Twins in the Burma-Thai boarder region.
Part two: Warrior Codes