The prevailing theory (supported by phylogenic evidence) holds that ancient fish actually evolved lungs to deal with decreasing oxygen concentrations in their home body of water. They used lungs to respirate using air above the surface. This was during the Devonian period. Later, this obviously facilitated the movement to terrestrial environments.
So they did not evolve air-breathing lungs for the purpose of moving to land...it was necessitated by increasing water temperatures, which rendered the existing gill respiratory systems inefficient. Lungs apparently evolved so the fish could keep living in water...