Yes, you can transplant it. Make sure the container is no more than 2 inches larger across the top than the old one is. Use a growing medium that is specially formulated for cacti and succulents ... the bag should be clearly marked as such. Do not water the cactus for a week or two before
you transplant it, and do not water it for a week or two afterward
. For cacti, the roots fare better during transplantation if everything is dry.