Skip to content

Instantly share code, notes, and snippets.

@1eedaegon
Last active May 3, 2025 03:19
Show Gist options
  • Save 1eedaegon/873f8952f8c82326280b07530112f6a7 to your computer and use it in GitHub Desktop.
Save 1eedaegon/873f8952f8c82326280b07530112f6a7 to your computer and use it in GitHub Desktop.
How to install python3.9 on ubuntu18.04

How to install python 3.9 on ubuntu 18.04

  • Install packages
  • Download python3.9
  • Build and install python binaries

Install packages

> 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

Download python3.9

> wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz

Extract python

> tar -xf Python-3.9.1.tgz

Check dependencies and test

> cd Python-3.9.1 && ./configure --enable-optimizations

Build using make file

> make -j 12

Install python

> sudo make altinstall

Check version and location

> python3.9 --version
Python 3.9.1

> which python3.9
/usr/local/bin/python3.9

Change default python

> 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment