How do I install Python 3.7 on Ubuntu 16.04 and 18.04? [duplicate]

I have several systems. Some are 16.04 mini-servers and I cannot update the OS yet. The others have been updated to Ubuntu 18.04. (The 18.04 version I used has Python 3.6.5 on it).


Currently there is no trusted PPA containing python 3.7, so you will have to build it yourself. Download desired version and follow the instruction on this documentation page.

It should be as easy as:

./configure
make
sudo make install

Update: Thank you to C14L, also now it is on doc page. make install can overwrite or masquerade the python3 binary. make altinstall is therefore recommended instead of make install since it only installs exec_prefix/bin/pythonversion

./configure
make
sudo make altinstall