China is to finance 90% of the first stage, put at $3.8bn (£2.3bn), with work carried out by a Chinese firm.
Construction work on the standard gauge line is expected to start in October this year, and the 610km (380-mile) stretch from the coast to Nairobi is due to be finished in early 2018.
A bill passed by MPs in Uganda which criminalises the transmission of HIV has been criticised by the campaign group Human Rights Watch (HRW).
Those who wilfully pass on HIV could face a fine of $1,900 (£1,130) or a 10-year jail term or both.
Pregnant women and their partners will also have to be tested for HIV and it allows medical providers to disclose a patient's HIV status to others.
Such measures would seriously impede the fight against Aids, HRW said.