You don't, technically, have to live in Canada.
On paper, you just have to be physically present in Canada for 731 days within the past 5 years (and the five year period is rolling, so at any point in time, you need to go back five years, and be able to count at least 731 days that you have been physically present in Canada). In theory, you can simply stay these 731 days in a five rolling year period in hotels or something, and you should still, theoretically, satisfy the 'residency' requirement.
However, CBSA and IRCC are suspicious of PRs that are cutting it way too close, and the best way to prove physical presence is by bona-fide full-time residency in Canada (i.e., you are working full time in Canada, you have a place of residence in Canada, you live in Canada, etc).