What about the first community ever to exist? You think they jus came up with it out of nowhere? You would prolly say something like, they were lonely and needed somethin to believe in i suppose?
Mostly it exists because it fulfils many human emotional needs. I'll list a few.
1. It answeres the unanswerable. Many people don't like to not know things.
2. It gives people a sense of control of their lives (pray for good harvest). This is how a lot of supersticions get started.
3. It gives the downtrodden hope of a better life to come.
4. It gives victims a sense of eternal justice. It is hard for many to accept that bad people will sometimes get away with doing bad things. It is much more comfortable to believe that they will be caught and punished by the devine.
5. It programs people to behave as the ruling elite want them to. Social control is a very big force behind religion.
6. It gives people a sense of identity and communion. People like to belong to groups. This is another group to belong to. And it usually comes with a set of outgroups to scorn and look down on.
7. It gives people pride via associaton. Much like how people do this with spots teams. The team they cheer for wins (or "will" win) and they feel like they have acomplished something great (even though they weren't even in the stadium).
8. It justifies the otherwise unjustifiable. Religion has been used to sell just about every kind of attrocity you could think of.
There's just a few off the top of my head. I'm sure there are many more.
Note that though all of these explain the popularity of religions none of them give any credence to any specific religion being truth.