On Towards the Stars: Dealing with Barbarians
[This post is part of a larger strategy guide for Civilization 6]
Barbarians are a balancing mechanic. If you're in your own area of the map and don't have to contend with nearby civilizations, you can ramp indefinitely and win the game. Barbarians make this a bit more difficult, because they force you to build at least SOME military. Even though you do get some early game bonuses for fighting barbarians, in general you want to try and avoid lengthy barbarian campaigns. Barbs will pillage your tiles, kill trade routes, capture builders and settlers, raze cities, and as a result force you to invest in military. Worse, barbarians are most annoying in the earliest part of the game, when you are trying to get your engine online. And in return for defeating barbs, you get a tiny amount of experience and maybe 30 gold. Understanding how barbs work and how to deal with them will hopefully save you a lot of early game restarts.
Barbarian Spawns and Deterrence
By default, barbarian camps spawn in areas of the map where no one has active visibility. In the early game, this happens everywhere; as time goes on, this will continue to occur primarily in tundras and deserts (because the rest of the landscape is settled by players). Note that in the early game, every civilization will have at least one barbarian camp spawn nearby (within 6 tiles or so).
Every barbarian camp will automatically unlock any tech that half the other civs have. At spawn, they will create the strongest anti cavalry unit they have access to, and the strongest recon unit they have access to. The former generally sticks around the camp, while the latter goes looking for civilizations to fuck up.
There are three kinds of spawn, based on the barb camp location. Melee camps are the default. Horseman camps spawn if the barbs are near horses. Pirate camps spawn if the barbs are on the coast. This is also roughly the order of how dangerous the different kinds of barbarians can be, especially early on. If a melee barb camp sends a few warriors and slingers your way, no big deal. But if a barb camp sends 2-3 galleys to one of your coastal cities, you better have some fucking defenses.
The easiest way to avoid barbarians is to prevent camps from ever spawning near you. Having any standing military posted around your unsettled borders is a great way to remove fog of war and prevent barbarian camps from being created in the first place. Obviously, this is easier said than done — in the early game, you likely won't have enough units to actually fully prevent barbarian spawns.
Note that in the BBG mod, barbarian camps spawn much more frequently and aggressively.
Barbarian raids and how to deal with them
If a barbarian unit (scout) finds your territory and makes it back to the camp, the camp will create 3-6 units, one for the next few turns, and send them towards your civilization.
In general, much of the advice from my post on defending against a surprise war applies. The added caveat is that you should use the Discipline card (+10 combat strength against barbarians). Hopefully this is…obvious? Because there's often at least one camp nearby, I have discipline locked in for a lot of the early game.
One small edge case to be wary of: if you destroy a barbarian camp, all associated barbs (including the scout) will just start ramming themselves into your city. This can be bad if they've already been doing that and your city's health is low. Barbarians raze cities every time they capture one (except your capital). This is also why dealing with barb boats is an absolute nightmare. The early galleys are pretty strong, and it's rare to have any sizable number boats of your own. I've lost more coastal cities than I'd care to admit to barbs on the coast.
Preventing raids
The easiest way to prevent a raid is to find the barb camp and kill it.
Since this is most common in the early game, I'll tailor the suggestions below to the ancient era. A few steps:
Find the camp. As you explore more of the map, this becomes easier. Later in the game, consider using the search tool in the minimap — new barb camps will show up with that tool, even in the fog of war.

Send a melee unit over to the camp. In the early game, this should be the warrior you spawned with. Don't worry about fielding your own boats immediately if you're on the coast; your galleys won't be able to kill a barb camp anyway.
If you don't have discipline in place, attack with your warrior once, then wait one turn to heal, then attack again. Any time your warrior has more health than the spearman in the camp, you should attack; otherwise heal. If done correctly, your warrior should get a promotion after ~3 attacks.
Regardless of the promotion choice, you should then be able to clear the camp.
If you're sending over a slinger, it's a bit more tricky and relies on terrain. First, find the camp as usual. Then:
Move your slinger so that you're on some sort of difficult terrain (hills, woods) within two tiles of the camp. The barb spearman should come out of the camp to chase down your slinger, but will have to stop on the tile in front of the slinger due to the terrain.
Attack with your slinger, and continue doing so until you get a promotion. The extra terrain protection should give you just enough defense to kill the barb spearman.
A more difficult way to prevent raids is to find and kill the barbarian scout1. Since scouts have more movement than most other units, this is pretty rare to pull off, and it also doesn't really solve the barbarian problem, but idk maybe it's worth talking about just in case.
Barbarian scouts will always move away from any unit that has more strength than it does (in the early game, that's any military unit). The most consistent way to get a scout is to use this technique to trap it between two other units and slowly move it towards a mountain or coast. I've used this trick exactly once, every other time I've killed a scout by luck. YMMV.
Barbarian scouts will also move towards trade routes and free builders/settlers. You can sometimes use these civilian units to bait the barbarian, but it is a very high risk play to lose otherwise solid units2.
Note that coastal barb camps can use galleys as scouts. These are hard to kill and there's no special strategy for doing so; your best bet is to end the camp before it becomes a problem.
And trade routes don’t get captured, so much as deleted. So in general, probably not worth baiting a scout with a trader.