Librarians are the most useful villagers in the game, because they sell enchanted books that an enchanting table can never produce.
Making a librarian
Any unemployed adult villager takes a job from a nearby workstation. Place a lectern within range and one of them claims it, turning into a librarian with green robes and a book.
Rerolling for the book you want
Before you trade with the villager even once, its offers can be re-rolled. Break the lectern, wait for the villager to lose its profession, then place the lectern again. It picks a new job and a new first trade. Repeat until the book you want appears.
The moment you complete a single trade, the offers lock permanently. Always check the trade window before buying anything, or you will lock in Bane of Arthropods forever.
Bringing the price down
Books can cost a painful number of emeralds at first. Curing a zombie villager slashes prices dramatically and permanently — splash it with a weakness potion, feed it a golden apple, and wait. A cured librarian often sells the same book for one or two emeralds.
Trading repeatedly also unlocks better deals as the villager levels up, and a villager whose workstation you keep nearby restocks twice a day.
What to buy first
Mending, then Unbreaking III, then whatever suits your gear. Mending is the one that changes how you play, because it removes gear replacement from the game entirely.
Once the books are in your chest, work out the cheapest combining order with the enchantment calculator before you touch an anvil — applying them one at a time is how people end up staring at “Too Expensive”.