Hi! So, basically, with cycling, what you're doing is building up a beneficial bacteria colony that will break down the fish's poop so the ammonia and nitrites can't harm him. Yes, if you're planning to cycle the tank without the betta, you want to do it before you purchase him. This is called a fishless cycle, because you are creating the bacteria colony without a fish involved. Some people cycle their tanks with their betta, but it's often more trouble than it's worth because you have to do extra water changes and often the betta gets very ill from the ammonia that builds up in the water.
If you want to do a fishless cycle, you basically need a source of ammonia to feed the bacteria in the tank and help them to multiply. It usually takes a tank about 2-4 weeks to fully cycle fishlessly. All decomposing organic matter releases ammonia, so some put fish food or a cocktail shrimp in their tank and let it rot. A less messy and more controlled way, however is to add drops of pure ammonia to the water daily.
If you're going to use pure ammonia, make sure it's 100% pure! It can't have any detergents or anything. Shake the bottle, and if it bubbles, it's no good. Pure ammonia can be hard to find but ACE Hardware store has their own brand of pure ammonia that is great for cycling. ALSO, you can go to your local pet store and ask for a cup of gravel from one of their healthy tanks. The gravel will already have good bacteria in it, and if you put it in your tank, it will speed up the process by A LOT. This is called "seeding" the tank.
Cycling can be kind of a pain because you want to go pick out your betta, but trust me, it's worth it in the long run! If you cycle your tank, you'll only have to do about 15% water changes weekly to keep the water clean and your betta will be much less stressed.
I touched on the basics here, here are some more pages on fishless cycling, mainly focusing on the pure ammonia method. Good luck and have fun! We are here for you every step of the way if you have questions.