- Install packages
- Download python3.9
- Build and install python binaries
> sudo apt update
> sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
> wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
> tar -xf Python-3.9.1.tgz
> cd Python-3.9.1 && ./configure --enable-optimizations
> make -j 12
> sudo make altinstall
> python3.9 --version
Python 3.9.1
> which python3.9
/usr/local/bin/python3.9
> sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 3
> sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/local/bin/python3.9 3 auto mode
1 /usr/bin/python2.7 1 manual mode
* 2 /usr/bin/python3.6 2 manual mode
3 /usr/local/bin/python3.9 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/local/bin/python3.9 to provide /usr/bin/python (python) in manual mode
If you got a warning like this:
WARNING: The script pip3.8 is installed in /usr/local/bin(EXAMPLE) which is not on PATH.
You need to add the following line to your ~/.bash_profile
or ~/.bashrc
or ~/.zshrc
file.
> echo 'export PATH="$HOME/usr/local/bin(EXAMPLE):$PATH"' >> ~/.bashrc