This is if funding talks with China fail to bear fruit, its president said.
Yoweri Museveni confirmed that Uganda had started negotiations with China on building the line that would link to Kenya, speeding up freight transport in the region. He gave no details about how far the talks had progressed.
"But if they don't (offer financing), we shall fund it ourselves," Museveni told Reuters on Monday on the sidelines of an African investment conference in London.
"Remember we have our oil, which we shall start harvesting in 2017, and that money will deal with these projects - railway and electricity ... China or no China, we shall build that railway."
The new line would run from the Kenyan border to Kampala, then north to South Sudan and west to the oil fields. It would supersede a narrow gauge line that now only operates to Kampala. The existing line, on which trains travel more slowly, has suffered from years of neglect. Most freight in Uganda goes by road.
Uganda believes that getting finance from China, which is helping build Kenya's new railway, would be cheaper than tapping international markets.
Uganda found commercial oil reserves in 2006 but production start dates have repeatedly been pushed back, partly because of disagreements with oil firms over whether to refine the crude in Uganda and partly due to the challenge of exporting from the landlocked nation.
Uganda was deemed to have commercially viable quantities of oil when recoverable reserves reached a threshold of 800 million barrels, a Ugandan official said. That figure has now reached 1.4 billion barrels and the discovery of oil in Kenya has made building a pipeline across both states more viable.
Oil prices, which have slipped from more than 110 dollars a barrel in June to well below $90 a barrel, affect viability though falls can be addressed in production contract terms that ensure returns for firms are enough to keep projects going.
Uganda wanted a refinery built with capacity to process 120,000 barrels per day (bpd), a plan oil firms said was not commercially viable. Both sides have since agreed to a refinery with initial capacity of 30,000 bpd, rising to 60,000 bpd later.
Uganda has signed up to a proposal with Kenya to build a pipeline running to a planned oil terminal on the northern Kenyan coast.
Separately, the president shrugged off concerns about the Somali militant group al Shabaab, after it vowed more attacks on countries such as Uganda which contribute troops to an African peacekeeping force in Somalia.
"Al Shabaab is not a danger to Uganda because it can't take root in Uganda," he said. "They are not supported by the population."
"They are just a threat if they are not attended to," he said.
The al Qaeda-aligned group, which promised more attacks after US missiles killed its leader in September, bombed sports bars in Kampala in 2010, killing 74 people. Last year, the group launched a deadly attack on a shopping mall in Kenya, another contributor to the African peacekeeping force.