Gunpowder is one of those weird things that are beyond crucial to the development of modern history but are also more than able to be created and used millennia before its OTL introduction.
Provided you have the appropriate amount of time to develop whatever techniques and technologies to make gunpowder widely used in weaponry. How does that affect the development of the civilizations of the Bronze Age (Hittites, Egyptians, Babylon) does it lead to more stable polities, wider urbanization, the aversion of cavalry armies altogether?
Assuming it does get invented, it would remain a secret knowledge of an high caste (of priest, maybe?). You would probably end up with the equivalent of the Gunpowder empires of OTL, where the state monopolized the military.
It would happen where there are absolute monarchies, but i don't know how innovative ancient empires were.
Anyway, i don't think that muskets will be invented as fast as it happened in OTL Europe. Maybe they'll use the as bombs or grenades, but with a standardized production.
Gunpowder could be used in sieges (like at Helm's deep
), or by planting mines on the battlefield. About fending off barbarians, i'm not sure, because OTL barbarians got to "civilize" quickly in OTL, basically everywhere.
Take note that the gunpoweder empires were led by mongol/turkic dynasties.
Anyway, i think that there is a misconception about gunpowder: everyone see its employment as the only solution to barbarian raids and colonization, but i think that military tactics/organization and logistics were more important than just having a musket. Consider that muskets were highly inefficent until the XVII century, and were often replaced by bows.
More than gunpowder, i think that to fend off barbarians you need coordinated infantry tactics.
So you need more widespread warfare in antiquity, and thus more political fragmentation. Perhaps a divided Palestine with warring city states?