Almost all of the libraries of the middle ages were located in monasteries.Later the universities were established by and for the priesthood.
In the early part of the middle ages illiteracy was almost complete.The only portion of the population that was generally literate were the monks and clergy.
Many monasteries committed themselves to preserving knowledge by painstakingly copying books by hand and keeping them for posterity Between their book binders, illustrators and copyists it might take two or more years to complete a Bible