We report the ab-initio study of rare-earth adatoms (Gd) on an insulating surface. This surface is of interest because of previous studies by scanning tunneling microscopy showing spin excitations of transition-metal adatoms. The present work is the first study of rare-earth spin-coupled adatoms, as well as the geometry effect of spin coupling and the underlying mechanism of ferromagnetic coupling. The exchange coupling between Gd atoms on the surface is calculated to be antiferromagnetic in a linear geometry and ferromagnetic in a diagonal geometry. We also find that the Gd dimers in these two geometries are similar to the nearest-neighbor and the next-nearest-neighbor Gd atoms in GdN bulk. We analyze how much direct exchange, superexchange, and Ruderman-Kittel-Kasuya-Yosida interactions contribute to the exchange coupling for both geometries by additional first-principles calculations of related model systems.