Seven years is the short answer, and it holds up. Joyce started Ulysses around 1914 and finished the manuscript in 1921, then waited to publish until his fortieth birthday. Measured against how dense the book turned out, seven years almost sounds quick.

The Direct Answer
About seven years, from roughly 1914 to 1921, with publication on February 2, 1922.
The dates are well documented, and Joyce even printed 'Trieste-Zurich-Paris, 1914-1921' at the close of Ulysses itself.

Seven Years, One Sentence at a Time

Joyce began serious work on Ulysses around 1914, the same year Dubliners finally reached print. He wrote through a world war and constant upheaval, moving his family more than once, and still the book grew slowly because that was simply how he worked. Chapters were serialized in the American magazine The Little Review from 1918 until 1920, when an obscenity prosecution over the 'Nausicaa' episode shut the serialization down.

I have been working hard on it all day. ... Two sentences.

James Joyce to Frank Budgen, from James Joyce and the Making of 'Ulysses'

Budgen had assumed a full day of labor meant pages. Joyce meant two sentences, worked over until their word order was exactly right. Multiply that patience across the eighteen episodes of the book and the seven-year timeline makes sense. For the wider habits behind it, read the full James Joyce writing routine.

Fast Next to Finnegans Wake

Seven years only looks slow until you meet the sequel. Finnegans Wake took Joyce about seventeen years, from 1922 to its publication in 1939, and for much of that stretch he referred to it only as 'Work in Progress.' By then his eyesight had collapsed further, and the prose had turned into a dense weave of puns and invented words that he built at a crawl. Against that, Ulysses was the brisk one.


What You Can Steal