|Facts : the ship mounted 64 megajoule railgun the Navy wants will have a range of ~200 miles. A 32 megajoule prototype already exists, so the idea is less science fiction and more an engineering and integration challenge.
The slugs will be guided, using guidance fins and some kind of sensor system. Guided artillery shells have existed for decades, and the electronics inside survive the acceleration just fine. I'm not sure how far along the Navy is in developing the ammunition but I think it can be taken for granted that they can do it.
The Navy is planning on taking another decade to actually build ships sporting railguns but this is probably a matter of budget and priorities. If there was a pressing need for such a weapon I think it could be deployed within a few years.
Once railguns become practical, would existing defenses work against the slugs?
Railgun shots will be moving at several kilometers per second on a ballistic trajectory. They have to contain ferrous metals and will probably have a significant radar cross section (and stealthing them might not be possible with existing materials due to the frictional heat from traveling at mach 7+). Travel through the atmosphere at several kilometers/second would super-heat the projectile making it show up brightly on infrared and maybe even visible light.
So you've got this glowing projectile streaking in from above, traveling several times faster than the bullets shot from a CWIS system. How would you defend against it?
One last comment : railgun shots would not be able to fly around searching for a target like a missile can. To fire at a ship, you'd need to know it's exact position and possibly paint it with a targeting laser. I'm assuming a swarm of cheap, stealthy drone aircraft would search the seas looking for the enemy ships and act as a spotter.
Also, railgun technology scales. Unlike chemical propellants where the explosion velocity limits your projectile velocity, if you throw more hardware into a railgun you can increase it's range and power smoothly and easily. Railguns with the same range as ICBMs are quite practical. I've been thinking that they would allow a nation without a decent Navy to build anti-ship "shore batteries".