First thing you have to make yourself clear is what is your purpose behind buying a bike. Actually different bikes are intended for different types of riding and some bikes are very specific. It is true most bikes are pretty versatile like you ride to work, to the market and off course for long drive too. Types of bikes are, road bikes, hybrids bikes, sportive bikes, mountain bikes, electric bikes, folding bikes etc.
After making your mind the kind of bike you want to buy, you need to set your budget. Even you can get bikes with lower cost but their quality will be poor. Specific need bikes will require higher budget.
Next step after deciding your budget and type of bike, is choosing a shop to buy a bike. Some decent brand of bikes comes from specialist shops and these shops having their own unique personality, try to listen the wording of the staff what they have mention about the bike features because you will need tires, tubes and other parts of the bike for replacement in future. You can get a deal of post check after a month for your bike from a good shop . They make sure after checking to the bike that everything is assembled properly and is still working well. The most important components of the bikes are the gear of the bikes, so you need to decide how much gear bike you want to buy. Bike shop guy will shows you how the gear works, then take the time to get familiar with them. Take a test ride of the bike you are going to buy. Many times manufacturers of the bikes make bike demos, where they offer you a test drive of range of their bikes, you can get information about this from your local bike shops , specially beginning of the year when new model are being introduced.
Another alternative option is you can buy second hand bikes, but you should take advice of the professional person for the situation of the used bike. If it is in better condition and not too old , with lower cost you can buy it. This is the better option if you are buying a bike to keep it for 2- 3 year only and than plan to resale it.