The Great Wall is the perfect solution.
Otherwise, build their counter unit: Chariots vs. axemen, axemen vs. spearmen.
If you don't have copper yet, then, you can build archers with Combat 1 and Shock.
Also, some empires have improved Unique Units to use in dealing with barbarians.
Inca - quechas start with Combat1 and 100% vs archers,
Mali and Babylonia's UU are archers and work well against all barbs when defending a city. Skirmishers work well pretty much anywhere.
Persia and Egypt's UU are chariots, which work well vs. axemen. Persia works well vs archers too.
Any Protective Leader will start your archers off with City Defense1 and Drill1, improving their chances of defending your city and can build walls faster, if you need those.
Native America does very well at dealing with barbs.
They have a PRO leader, so the above applies, plus their Unique building monument grants +3xp to their archers. This means 2 promotions above the City1 & Drill1. So, City3 for your City defenders and Combat1 & Shock for your defenders on open tiles. Guerilla1 & 2 for archers defending copper, iron, gold etc, that appear on hills.
Their UU is an axeman that doesn't need copper and has +100% vs. melee. So, barb axemen and spearmen are easier to defend against, especially when on a hill or forest tile and when you might not have a chance to hook up your copper yet.
In my current game, I have Unrestricted leaders checked and chose Montezuma of Maya.
My AGG trait gives my Holkans Combat 1. I got the random event that grants cover to all melee units. So, my next promotions are Shock and Combat2. Holkans are immune to first strikes, so they are great archer killers and are already great chariot killers vs the AIs.