ogilvie was born in monymusk, aberdeenshire, the eldest son of the reverend alexander ogilvie, headmaster of robert gordon's college, aberdeen, and his wife maria matilda (née nicoll). his younger sister, dame maria gordon, was an eminent scientist in the fields of geology and palaeontology.