He remained in Aberdeen as a tutor till 13 May 1831, when he was appointed mathematical master in Gordon's Hospital, an educational establishment in the city.
Ogilvie died of typhoid fever at Aberdeen on 21 November 1867.