If there is one thing archaeology has shown, it is that humans, all human ancestors capable of rational thought at least, have had a concept of "god" likely as long as we have been around. Why is an interesting but, as yet, unanswerable question.
I have read somewhere that some anthropolgists view religon as a tool created by man.
Man is a tool maker. Man makes tools to control his enviornment - he makes fire - clothes - shelter - hunting impalements.
So man was faced with aspects of nature that he needed or wanted to control - like birth and death and the hunt. Man then invented ritual as a tool that he thought would give him control/influence over nature. This ritual became religion as man saw that whatever he was doing went along with his goals.
If I can give one example - the Aztec use of ritual human sacrifice as a tool to control the elements to produce good crop weather.
The Aztecs actually thought what they were doing was linked to good crop weather. When the Spanish put a stop to human sacrifice the Natives were terrified. They thought it would no longer rain - the seasons would not change - they could not understand why the Spanish did not understand this.
When the weather changed anyway without any human sacrifice the Aztecs were shocked. They dumped their religion almost overnight because they saw that as a tool it was meaningless to what they needed.
That is the rationlist version of why man has religion.