How exactly are you installing the libraries ?
What is the full path to your sketchbook folder ?
Does the sketchbook folder have a libraries folder within it and if so, what folders are within it ?
Which version of the IDE?
Where are your sketches and libraries located? On C:\Users\yourUsername\Documents\Arduino? Or on some network drive / onedrive?
I am installing library from the IDE itself
like Tools > Library manager > then I search for U8g2 and download it
for the path to library C:\Users\Myusername\OneDrive\Documents\Arduino\libraries
It might. I don't use onedrive so don't know but testing should be easy.
Change the sketchbook directory in file → preferences in the IDE.
Install a (problematic) library, open an example and check if it compiles.
If it compiles, you know that it's onedrive related. I don't know if there is a solution but you might find one using e.g. arduino onedrive - Google Search