Content caching in user devices with device-to-device (D2D) communication capacities is becoming a promising technique to address the data traffic explosion problem in the next generation mobile networks. In this paper, we develop a socially aware distributed caching strategy based on a decentralized learning automaton, referred to as the Discrete Generalized Pursuit Algorithm (DGPA), to optimize the cache placement operation in D2D networks. Different from existing caching schemes, the proposed algorithm not only considers the file request probability and the closeness of devices as measured by their distance, but also takes into account the social relationship between D2D users. Furthermore, we characterize the mutual impact between the contents cached in different D2D users. Simulation results show that the proposed algorithm converges quickly and outperforms its counterparts using deterministic caching and random caching. Our work sheds new insights on the optimal design of D2D cache placement operations.