Both combine many models into one. Beyond that, they don't have much in common — one trains in parallel to cancel out variance, the other trains in sequence to grind down bias.
"Ensemble learning" is often taught as a single bucket — combine several models and the result beats any one of them. That framing hides the fact that bagging and boosting are solving two different problems with two different architectures. Bagging (bootstrap aggregating) trains many models in parallel, each on its own random resample of the training data, then averages or votes their predictions together — this cancels out variance. Boosting trains models in sequence, where each new model is deliberately built to fix the errors the previous models left behind — this grinds down bias. Random Forest is bagging; AdaBoost, Gradient Boosting, and XGBoost are boosting. Picking between them isn't a coin flip — it depends on which kind of error your model actually has.