(Abridged) Context: The assumption of a gas-to-dust mass ratio (gamma) is a common approach to estimate the basic properties of molecular clouds, such as total mass and column density of molecular hydrogen, from (sub)mm continuum observations of the dust. In the Milky Way a single value is used at all galactocentric radii, independently of the observed metallicity gradients. Both models and extragalactic observations suggest that this quantity increases for decreasing metallicity Z, typical of the outer regions in disks, where fewer heavy elements are available to form dust grains. Aims: We aim to investigate the variation of the gas-to-dust ratio as a function of galactocentric radius and metallicity, to allow a more accurate characterisation of the quantity of molecular gas across the galactic disk, as derived from observations of the dust. Methods: Observations of the optically thin C$^{18}$O (2-1) transition were obtained with the APEX telescope for a sample of 23 massive and dense star-forming regions in the far outer Galaxy (galactocentric distance greater than 14 kpc). From the modelling of this line and of the spectral energy distribution of the selected clumps we computed the gas-to-dust ratio and compared it to that of well-studied sources from the ATLASGAL TOP100 sample in the inner galactic disk. Results: The gradient in gas-to-dust ratio is found to be 0.087 dex/kpc (or equivalently gamma proportional to Z$^{-1.4}$). The dust-to-metal ratio, decreases with galactocentric radius, which is the most common situation also for external late-type galaxies. This suggests that grain growth dominates over destruction. The predicted gas-to-dust ratio is in excellent agreement with the estimates in Magellanic clouds, for the appropriate value of Z.