Hello, 👋
In this article I will show you how to install Python versions on Linux using the following methods: compiling from source, dead snakes ppa and pyenv.
To make things easier, if you want to follow along in an environment that you can break, you can create a local Kubernetes cluster using Minikube.
Next, I’m going to use the following yaml file to create an Ubuntu pod:
|
|
Save the above yaml in a file ubuntu_pod.yaml and run:
|
|
To get a shell on the Ubuntu pod, run:
|
|
To start from scratch, simply delete the pod with kubectl delete pod/ubuntu and then recreate it.
Compiling Python from source
Before compiling Python, you will need to setup the build environment, thankfully, it is straightforward.
Pyenv has great instructions on it: .
On Ubuntu, to build Python, install the following packages:
|
|
Then, search the desired python version here and, for example to install Python 3.9, run:
|
|
Then, run configure:
|
|
And finally run make install if you want to replace the default Python installation or make altinstall to install python under the binary name of python3.9
make altinstall
To test the installation run:
|
|
Installing Python via a third party PPA deadsnakes
To install Python using the deadsnakes ppa run:
|
|
Then, to test the installation run:
|
|
Installing Python via Pyenv
I already written an article on how to install Python using Pyenv, check it out if you wish.
https://nuculabs.dev/posts//2020/06/27/pyenv-for-linux-users/
Thanks for reading! 📚