There are three main factors to consider -- age, condition and cost.
Age: If your roof is less than 12 to 15 years old, it’s probably fine.
Condition: Check for red flags, both inside and out. Signs of water damage (leaks or stains) on your ceiling may include outside light coming through the roof, broken, cracked or missing shingles, or shingle granules in the gutters.
Cost: The cost of repairing or replacing a roof varies depending on the material of the roof surface and where you live. Weather, such as snow load or rain amount, may be a factor in determining replacement cost.
A general rule of thumb is if your roof needs to be replaced within five years, you should consider doing it before installing solar panels. Removing and reinstalling solar panels to replace the roof generally come with an extra cost. This can be prevented if you repair the roof prior to installing your solar system.