Swift imagined books battling. In a library described in one of his satires, the volumes do not remain on the shelves but hurl themselves across the room in an exchange of insults and fisticuffs, enacting their disagreements by tearing one another's pages out. What happens, however, when the lights go out? Those belligerent books probably settle down to make love and breed other books. Writers write because they are compulsive readers and they do so in book-lined rooms. Forget about art imitating life: literature is a self-generating, self-referring activity.

The Argentinian bibliophile Alberto Manguel, whose books include A History of Reading, is an expert on this snugly closed circle, symbolised by the private library he has installed in a 15th-century barn in the Loire. Here he sits, preferably at night, with the 'shapeless universe' outside expunged by darkness. Warmed by the pools of light that spill from his lamps, he does not even need to read: the smell of the wooden shelves and 'the musky perfume of the leather bindings' is enough to pacify him and prepare him for sleep. Although the softly sifting 'plankton of dust' shed both by the crinkled pages and his drying skin anticipate a longer sleep, he does not mind. Libraries are storeyed tombs and Manguel is happy to be housed in the funereal stacks.

Within his global, multilingual book collection, he can effortlessly travel in both time and space. He admits the megalomania of the enterprise: it recalls both the hubris of the Tower of Babel, felled by a resentful God, and the acquisitive mania of the library at Alexandria, accidentally torched when Caesar set fire to his own ships. Behind these imperious ventures, and behind Manguel's life-long scavenging in second-hand shops, lies a desire to demonstrate the unity of phenomena, the indexed connection between disparate experiences and the accessibility of all this lore to a single individual.

No wonder God toppled the first skyscraper: the Bible, once described by believers as 'the good book', aims to pre-empt all other books, so the personal libraries we piece together announce our defiant conviction that truth is partial and relative, a collaborative construction, not an utterance by some authority on high. In 1752, Diderot's enlightened Encyclopaedia, described by Manguel as 'an archival and interactive library', was accused of blasphemy because in its tabulation of all human knowledge it pointedly found no room for religion.

Alphabetising their stock or relying on fractionalised decimals like Dewey, librarians are obsessive classifiers who impose on chaos an order they know to be fictional and false. Their crazed logic makes libraries, as Manguel says, 'pleasantly mad places'. Carlyle once characterised the old reading room at the British Museum as a psychiatric ward where 'people in a state of imbecility' twitched and muttered as they thumbed unreadable tomes.

Manguel can seem a little anal and anoraky. Since I shelve my books associatively, I'm less than engrossed by his worry about whether to place Garcia Lorca under G or L; it's not surprising to learn that when Manguel was living in Toronto, he crammed extra bookshelves into the bedrooms, corridors and even the bathroom, so that his children complained that 'they required a library card to enter their own home'.

But The Library at Night, fortunately, is more than a tour of the microcosm contained in Manguel's converted barn. Its fondness for leathery bindings and its fussy annoyance about the 'evil white scabs' of price-stickers slimily glued to book jackets soon give way to a crusading defence of the library as a mental sanctuary, a repository of memory, the only kind of home that has any emotional value for Manguel the deracinated cosmopolitan.

The defence is necessary because libraries like his are now imperilled by their virtual equivalents on the internet. A book read on a screen has dematerialised; we can neither own nor love it, and if we can't hold it in our hands how can we absorb it into our minds?

As Manguel ruefully observes, the 'multimedia library' of the web inverts and potentially erases the universal library of which Renaissance humanists dreamed. The traditional library was a citadel sacred to the notion of omniscience; the web, by contrast, is 'the emblem of our ambition of omnipresence', like a supermarket that boundlessly proliferates in space and deluges the planet with its tacky wares. 'The library that contained everything,' Manguel laments, 'has become the library that contains anything.' No wonder he values the spatial enclosure of his nocturnal barn, whose shelves and thick stone walls serve the purpose of exclusion.

Manguel is old, wise and sad enough to know that the future belongs to the users of the Kindle reading device and to oafish librarians who discard books as landfill after transferring their contents to disks or CD-Roms that may be illegible in a decade. He therefore likens his own library to the coffin of native earth that Dracula carries with him from Transylvania to London. It's a good joke, but it's unjust. Milton said that a great book was 'the precious lifeblood of a master spirit': literally an infusion or transfusion of life, not a portable grave in which the undead quietly slumber. Reading, as Manguel knows, is 'a ritual of rebirth', which both invigorates the reader and awakens old books to new life. He shows what he means by describing his dreams of a fluid subliminal library, a place where the hero of Kafka's The Castle sails off in a quest for the Holy Grail on the whaling vessel from Melville's Moby Dick, then after a shipwreck lands on an island where, like Crusoe, he reconstructs civilisation by consulting the three bibles he has salvaged from the wreck. Books jump out of their jackets when Manguel opens them and dance in delight as they make contact with his ingenious, voluminous brain. He is not the keeper of a silent cemetery, but a master of bibliographical revels.

Brought to book: a history

47AD

The library of Alexandria is destroyed by fire. It was said to contain a copy of every book on Earth.

868

The world's oldest surviving book, a woodblock-printed version of The Diamond Sutra, is made in China.