Programming/Python

How to Install Python 3.8 on Ubuntu 18.04

onsight 2022. 6. 29. 08:01

Installing Python 3.8 on Ubuntu with Apt #

Installing Python 3.8 on Ubuntu with apt is a relatively straightforward process and takes only a few minutes:

Run the following commands as root or user with sudo access to update the packages list and install the prerequisites:

  1. sudo apt update``sudo apt install software-properties-common
  2. Add the deadsnakes PPA to your system’s sources list:When prompted press Enter to continue:
  3. Press [ENTER] to continue or Ctrl-c to cancel adding it.
  4. sudo add-apt-repository ppa:deadsnakes/ppa
  5. Once the repository is enabled, install Python 3.8 with:
  6. sudo apt install python3.8
  7. Verify that the installation was successful by typing: At this point, Python 3.8 is installed on your Ubuntu system, and you can start using it.
  8. Python 3.8.0
  9. python3.8 --version

Installing Python 3.8 on Ubuntu from Source #

In this section, we’ll explain how to compile Python 3.8 from the source.

Update the packages list and install the packages necessary to build Python:

  1. 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
  2. Download the latest release’s source code from the Python download page using wget :At the time of writing this article, the latest release is 3.8.0.
  3. wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
  4. When the download finishes, extract the gzipped archive :
  5. tar -xf Python-3.8.0.tgz
  6. Switch to the Python source directory and execute the configure script which performs a number of checks to make sure all of the dependencies on your system are present:The --enable-optimizations option optimizes the Python binary by running multiple tests. This makes the build process slower.
  7. cd Python-3.8.0``./configure --enable-optimizations
  8. Start the Python 3.8 build process:For faster build time, modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.
  9. make -j 8
  10. When the build process is complete, install the Python binaries by typing:Do not use the standard make install as it will overwrite the default system python3 binary.
  11. sudo make altinstall
  12. That’s it. Python 3.8 has been installed and ready to be used. Verify it by typing:The output should show the Python version:
  13. Python 3.8.0
  14. python3.8 --version

source : https://linuxize.com/post/how-to-install-python-3-8-on-ubuntu-18-04/