Title pretty much says it. It seems almost every city (at least in the US) has one, were they always so ubiquitous?
For the physical ubiquitous-ness of American libraries you largely have one man to thank, Andrew Carnegie. While there were a few libraries in America before, mostly "subscription libraries" which are thin on the ground these days but still around; Boston Athenaeum is probably the most well known, but the idea of the free public library, taxpayer supported, dates only to about the turn of the century.
Andrew Carnegie in his later years was a devotee of charity, but he was fussy about it. He didn't like just giving money to poor people, because he thought they'd just waste it on non-improving things. (Here's a succinct overview of his charity philosophy in poster form.) Andrew Carnegie's system worked like this: he would pay for the building and nothing else. He would not pay for the books, or the staff, or to keep the lights on, just the building, and usually not even all of that, often he'd sometimes give part if the money required to build a library and then another local donor would cough up the rest for the building. But there was a big catch - the city had to prove that the library would be self-supporting before they'd get the money from him to build it. But this was a rather ingenious idea, because it made the library free, but only temporarily a charity. This insistence on city support, not charity support which is rather fickle, is (in my rather unhumble opinion) what has made the American system of public libraries so incredibly strong and long-lasting. Carnegie got the American library system going just by giving away buildings, but he didn't keep it going, taxes did that.
There's also a little side benefit to him not giving away books, which is that collections were regional and not homogeneous. Local librarians would select and purchase their own books with their own money, and not get say the Carnegie 100 Book Starter Kit or something, which has some pretty far-reaching impacts in terms of freedom of thought.
So that's why just about every cowpatty town in America manages to have a bar, a post office and a library. :)
The Wikipedia on this doesn't give a bad overview, and reading the lists of Carnegie libraries still standing is a real pleasure, but if you want to get serious Free to All: CARNEGIE LIBRARIES & AMERICAN CULTURE, 1890-1920 is quite good, I confess I haven't read all of it though! And here's an assortment of images of Carnegie libraries if you'd just like to look at them.
I can talk more about the history of libraries in America if you have other questions as well.