Context. In cold (T < 25 K) and dense (n H > 10 4 cm −3 ) interstellar clouds, molecules such as CO are significantly frozen onto dust grain surfaces. Deuterium fractionation is known to be very efficient in these conditions as CO limits the abundance of H + 3 , which is the starting point of deuterium chemistry. In particular, N 2 D + is an excellent tracer of dense and cold gas in star-forming regions. Aims. We measure the deuterium fraction, R D , and the CO depletion factor, f d , towards a number of starless and protostellar cores in the L1688 region of the Ophiuchus molecular cloud complex and search for variations based upon environmental differences across L1688. The kinematic properties of the dense gas traced by the N 2 H + and N 2 D + (1−0) lines are also discussed. Methods. Deuterium fraction has been measured via observations of the J = 1−0 transition of N 2 H + and N 2 D + towards 33 dense cores in different regions of L1688. We estimated the CO depletion factor using C 17 O(1−0) and 850 µm dust continuum emission from the SCUBA survey. We carried out all line observations with the IRAM 30 m antenna.Results. The dense cores show large ( 2−40%) deuterium fractions with significant variations between the sub-regions of L1688. The CO depletion factor also varies from one region to another (between 1 and 7). Two different correlations are found between deuterium fraction and CO depletion factor: cores in regions A, B2, and I show increasing R D with increasing f d , similar to previous studies of deuterium fraction in pre-stellar cores; cores in regions B1, B1B2, C, E, F, and H show a steeper R D − f d correlation with large deuterium fractions occurring in fairly quiescent gas with relatively low CO freeze-out factors. These are probably recently formed, centrally concentrated starless cores, which have not yet started the contraction phase towards protostellar formation. We also find that the deuterium fraction is affected by the amount of turbulence, dust temperature, and distance from heating sources in all regions of L1688, although no clear trend is found. Conclusions. The deuterium fraction and amount of CO freeze-out are sensitive to environmental conditions and their variations across L1688 show that regions of the same molecular cloud experience different dynamical, thermal, and chemical histories with consequences for current star formation efficiency and characteristics of future stellar systems. The large pressures present in L1688 may induce the formation of small dense starless cores, unresolved with our beam, where the R D − f d relation appears to deviate from that expected from chemical models. We predict that high angular resolution observations will reconcile observations with theory.