The story
From rail + gun. * (railway gun): From being a gun mounted on a rail car, and being railroad-mobile. * (EM gun): From being a projectile ejecting device with a pair of electric conducting rails that a launch sled runs along, which shoots the projectile.
Etymology from Wiktionary, CC BY-SA 4.0.