His name was entered at Trinity College, Cambridge, on 3 July 1810, but on 10 January 1811 he migrated to Pembroke, from where he matriculated in the Michaelmas term of 1811, gaining a scholarship.
He graduated BA in 1815, when he was Eighth Wrangler, and the same year was elected a Fellow of his college.
[3] In 1829 he married Emily, a daughter of William Coxhead Marsh, of Park Hall, Theydon Garnon, Essex.
[4] In succession, Ainslie and his predecessor Joseph Turner held the Mastership of Pembroke College for a total of eighty-six years, becoming the two longest-serving Masters.
Ainslie died at the Master's Lodge, Pembroke College, on 9 January 1870, leaving an estate valued at some £12,000.