Finding and Preparing a Villager
The first step in making a villager into a librarian is locating an unemployed villager in a village or curing a zombie villager. According to the Minecraft Wiki, villagers will not take up a profession unless they are unemployed, which means they don't already have a linked workstation or profession.
Once you've identified an unemployed villager, it's important to make sure they can access the lectern workstation at all times. The Minecraft Wiki notes that villagers must be able to pathfind to their job site blocks to link with them and take on a profession. Keep the area around the lectern free of obstructions.
You'll also need to have patience when trying to get a villager to link with a workstation. The process can take some time and multiple in-game days. Villagers will detect and claim workstations up to 64 blocks away horizontally and 16 blocks vertically according to the Minecraft Forum. Give them time to detect and walk to the lectern to link up.
Creating and Placing Lecterns
To create a lectern in Minecraft, open the 3x3 crafting grid and place 4 wooden planks in the bottom row. Then place 1 book in the top middle slot (Source). This will craft 1 lectern which you can then place down in the world.
It's important to place the lectern near the unemployed villager you want to turn into a librarian (Source). The villager will be drawn to the lectern and link to it as their new job site block. Make sure to leave enough space for the villager to access the lectern.
If the librarian villager does not offer the enchanted books you desire, you can break and replace the lectern to force them to reroll their trade options. Each lectern replacement reshuffles the possible trades (Source). Keep breaking and replacing until the villager offers the books you want.
Waiting for Villager to Link to Lectern
After placing a lectern near an unemployed villager, you need to give the villager time to notice the lectern and walk over to inspect it. This process can take a while, even if the lectern is right next to the villager. Be patient, as it can take up to several in-game days for a villager to link to a lectern.
Watch for particle effects emitted from the villager and lectern to confirm when the villager has successfully linked to the lectern. Green sparkles will appear briefly above the villager's head when they first notice the lectern. More green sparkles will appear when they walk up to inspect and link to the lectern. These visual cues indicate the process is working, even if it's taking a long time.
On average, it takes around 1-2 in-game days for a villager to link to a lectern on Bedrock edition, and 2-5 days on Java edition. However, there are reports of it taking over 5-10 days in some cases!   If your villager is taking an especially long time to connect, try breaking and replacing the lectern to force them to recheck it.
Overall, you just need to be patient in this process. Ensure the lectern is accessible and wait for the villager to eventually link up. The more in-game days that pass, the more likely it is they will claim the lectern and transform into a librarian.
Getting Desired Trades
Once a villager has linked to a lectern and become a librarian, you can trade with them to get enchanted books. However, the enchantments they offer will be random at first. To get the specific enchantments you want, like Mending, you'll need to repeatedly break and replace their lectern until their trades change.
According to the Minecraft Wiki, librarian villagers have a 50% chance to sell enchanted books at lower trade tiers, and a 33% chance at the expert level. So you may need to break and replace their lectern many times before getting the desired book.
It's also important to trade with the librarian villager to unlock higher tiers of trades. Each tier unlocks more potential books. For novice, apprentice, journeyman, and expert, you'll need to trade approximately 2, 4, 8, and 12 times respectively.
If you're having a lot of trouble getting a specific enchantment like Mending, try isolating the lectern in an enclosed space. This prevents other villagers from linking to it. You can also isolate the librarian in a 1x1 space with just their lectern to repeatedly reroll trades.
Creating an Efficient Trading Hall
An efficient trading hall design is key to having a productive and useful trading system. There are a few key elements to focus on when creating an efficient hall:
Build stalls to separate and contain villagers - Stalls confine villagers to one block space, making it easy to trade with each one individually. Stalls can be made with glass, fences, trapdoors, or other blocks. Make sure there is enough space for the villager, the player, and any water streams or bubble columns used to transport villagers. See this stall design tutorial for examples: https://www.youtube.com/watch?v=r_Jc2Cw6ho8
Use rails or water streams to move villagers around - Minecart rails or water streams with soul sand or magma blocks under them make it easy to transport villagers into trading stalls from a holding cell. Rails keep villagers contained but water streams allow more villagers in transit. Water stream designs are covered in this tutorial: https://www.youtube.com/watch?v=oeesCRfaabg
Optimize hall for easy trading access to many librarians - Make sure the hall design allows the player to quickly and easily run past all the trading stalls. Long halls with two rows of villagers are common. Central water/rail transport and good lighting also helps. See examples of hall layouts here: https://www.digminecraft.com/farming/villager_trading_hall.php