Generally speaking, hamsters live longer in captivity than in the wild. This, in fact, is true of many animals. You can increase the lifespan of your hamster by providing vitamins in their water and taking extra good care of them in general. Clean their cage frequently to prevent disease. Change the water frequently as well and don't allow it to get slimy as this could also give your hamster an infection. Supplementing their diet with fresh food such as kale, spinach, lettuce, carrots, mashed sweet potatoes, and eggs will also help your hamster live longer.
I have always wanted rabbits, however, but refused to get them again if I had to keep them caged up in one of those tiny squares people typically keep them in. You know the ones, with wire floors and nowhere to go. Being a free spirit myself, I couldn’t imagine keeping something if it had to be caged up.