Maybe. Before trying medication, you may want to check and be sure you are promoting sleep. Avoid caffeine late in the day. Go to sleep around the same time in a quiet dark comfortable place. Get regular exercise during the day, but not too close to bedtime. Don't eat heavy meals close to bedtime. Avoid excess alcohol. If you are doing these things, and still can't get to sleep, see your doctor.
Slow down. First ask why am i having insomnia. Try good sleep hygiene first (google sleep hygiene for good tips). Make sure to get regular exercise and no heavy meals right before bedtime. If this is not helpful, then talk with your doctor. There are a number of medications that can help you slee other than "sleeping pills", which can be habit forming.