As a child, Gilbert travelled to Italy in 1838 and then France for two years with his parents, who finally returned to settle in London in 1847. He was educated at Boulogne, France, from the age of seven (he later kept his diary in French so that the servants could not read it), then at Western Grammar School, Brompton, London, and then at the Great Ealing School, where he became head boy and wrote plays for school performances and painted scenery. He then attended King's College London, graduating in 1856. He intended to take the examinations for a commission in the Royal Artillery, but with the end of the Crimean War, fewer recruits were needed, and the only commission available to Gilbert would have been in a line regiment. Instead he joined the Civil Service: he was an assistant clerk in the Privy Council Office for four years and hated it. In 1859, he joined the Militia, a part-time volunteer force formed for the defence of Britain, which he served in until 1878 (in between writing and other work), reaching the rank of Captain. In 1863, he received a bequest of £300 that he used to leave the civil service and take up a brief career as a barrister (he had already entered the Inner Temple as a student). His legal practice was not successful, averaging just five clients a year.