For reuse of code.
A good library consists of accurate, readable and reusable snippets of codes, usually functions and objects. When a programmer wants to build something, s/he needs to know the context and all the areas into which the working of his/her application is based on. Building everything from the scratch takes much time and effort. Having a library which can cater to the need of the programmer can save us from reinventing the wheel.
In some programming languages even the basic program of console outputs require us to import/use libraries so that we can concentrate on the work that we are doing instead of focusing on the working of how inputs and outputs are handled by the machine.
Libraries provide a certain level of abstraction which enables the programmer to work exactly on what is required by using the resources which have already been built.(As said by Franky)