MacGregor was born in Halifax in Nova Scotia on 31 March 1852, the son of Rev Peter Gordon MacGregor. He was educated there at the Free Church Academy in Halifax going on to study at Dalhousie University, where he graduated with an MA. He left Nova Scotia to pursue postgraduate studies at the University of Edinburgh, the University of Leipzig and the University of London.