Reconfigurable intelligent surface (RIS) technology is a promising method to enhance wireless communications services and to realize the smart radio environment. In this paper, we investigate the application of RIS in D2D communications, and maximize the sum of the transmission rate of the D2D underlaying networks in a new perspective. Instead of solving similarly formulated resource allocation problems for D2D communications, this paper treats the wireless environment as a variable by adjusting the position and phase shift of the RIS. To solve this non-convex problem, we propose a novel double deep Q-network (DDQN) based structure which is able to achieve the near-optimal performance with lower complexity and enhanced robustness. Simulation results illustrate that the proposed DDQN based structure can achieve a higher uplink rate compared to the benchmarks, meanwhile meeting the quality of service (QoS) requirements at the base station (BS) and D2D receivers.