Gibraltar has no train station.
The nearest train station is the Algeciras Train Station, located 20 km. from Gibraltar.
From Algeciras, the best option is to take the bus line M-120 to the Linea de la Concepcion and once there, to walk to the border with Gibraltar.
From Gibraltar, must go to La Linea de la Concepcion and take the M-120 bus line to Algeciras.