He graduated from Glasgow University in 1825 at the age of 17 and moved to Edinburgh where he taught mathematics and science at the Leith Mechanics' Institute, achieving the highest attendance in the city.