The Trans-Siberian Railway is definitely the longest railway in the world. It starts at Moscow and 9,289 km and seven days later, it finishes in Vladivostok. There are a great many intersecting and parallel railways that are associated with it including the Trans-Manchurian and the Trans-Mongolian, The BAM and Little BAM.
The Trans-Siberian Railway is a miracle of modern engineering through an extremely hostile environment.
Trans-Siberian Handbook by Bryn Thomas.