1. Enable “Files user interface allows sharing files with libraries”.

2. To share, select “Share with Library”.

Note:
This feature is disabled by default. Administrator has to enable it.
We can use Salesforce Apex also to share with a library. ContentDocumentLink record should be created with LinkedEntityId as the Library Id to upload a File to a specific Library Folder using Salesforce Apex.