 He was the eldest of eleven children, eight of whom survived until adulthood.He was educated at Penicuik Parish School 1806-11 and then the High School in Edinburgh.He then attended university both in Edinburgh (1814–17) and Geneva (1817-18).