Skip to content

Instantly share code, notes, and snippets.

@ptantiku
Last active April 14, 2023 12:31
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save ptantiku/aca8d955296d5dee01bd9ed1c3027d8c to your computer and use it in GitHub Desktop.
Save ptantiku/aca8d955296d5dee01bd9ed1c3027d8c to your computer and use it in GitHub Desktop.
Setup Python3.8 in Ubuntu Xenial (16.04 LTS). The python version was fixed at Python 3.5.1
#!/bin/sh
# install PPA
sudo add-apt-repository ppa:deadsnakes/ppa
# update and install
sudo apt update
sudo apt install python3.8 python3.8-dev python3.8-venv
# setup alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
# show menu for selecting the version
sudo update-alternatives --config python3
# or one command to set it
# sudo update-alternatives --set python3 /usr/bin/python3.8
@ptantiku
Copy link
Author

ptantiku commented Jan 8, 2020

install pip for the specific version

curl https://bootstrap.pypa.io/get-pip.py | sudo python3.8

@AnandShiva
Copy link

Thanks a ton. I wasted so much time looking for this. This process should be easier though. Any good libraries or best practices for installing python on servers?

@ptantiku
Copy link
Author

ptantiku commented Feb 1, 2021

Thanks a ton. I wasted so much time looking for this. This process should be easier though. Any good libraries or best practices for installing python on servers?

I think installing it with apt install python3 should be a proper way to do as to install the base python, unless you want to customize python version for specific app.
In that case, I prefer to dockerize the app and deploy it with Docker.

@bertarends
Copy link

Thanks a lot, this was also for me very helpfull.
I have a Ubuntu 16.04 server instalation with python 3.5.2. included but not pip.
Installed pip with apt install pip3. I got an old 8. version. Installing packages gave errors. Trying to update pip broke pip.
Now installed python3.8 and pip3.8 with your script. Everything works fine !

@TheGardenMan
Copy link

Thank you so much

@natyarteagac
Copy link

Thank you so so so so much!

@Seleucia
Copy link

Seleucia commented Nov 4, 2021

It is not workon
Description: Ubuntu 16.04.7 LTS
Release: 16.04
Codename: xenial

I'm still getting : E: Couldn't find any package by glob 'python3.8'

@ozbillwang
Copy link

ozbillwang commented Jan 23, 2022

it doesn't work any more

duplicate this issue with a Dockerfile

$ cat Dockerfile

FROM ubuntu:xenial

RUN apt update
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa -y
RUN apt update
RUN apt install -y python3.8

build the image

$ docker build -t demo . 

...
 > [6/6] RUN apt install -y python3.8:
#9 0.222
#9 0.222 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#9 0.222
#9 0.224 Reading package lists...
#9 0.960 Building dependency tree...
#9 1.098 Reading state information...
#9 1.148 E: Unable to locate package python3.8
#9 1.148 E: Couldn't find any package by glob 'python3.8'
#9 1.148 E: Couldn't find any package by regex 'python3.8'

update

seems deadsnakes team doesn't support ubuntu xenial (16.04) any more.

ref: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

image

I gave up, have to switch to Ubuntu Bionic or Focal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment