The board of library trustees may purchase real property, and erect or rent and equip, such buildings or rooms, as may be necessary, when in its judgment a suitable building, or portion thereof, has not been provided by the legislative body of the municipality for the library.