bad_coder9042093
bad_coder9042093

Reputation: 349

How to update python to latest version and set as default

I am currently on ubuntu 18.04.

My default python version is Python 3.7.9

I wanted to upgrade it to Python 3.9.2 and set it as default python version

How do I do that ?

Upvotes: 3

Views: 14280

Answers (2)

furas
furas

Reputation: 142641

If you don't have it in apt then you can add special repo deadsnakes Python repo for Ubuntu.
And after adding repo you should have all versions in apt form 2.3 to 3.10

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

sudo apt install python3.9

And later you can find path to actuall version

which python

and replace is with python3.9 which you can also find with

which python3.9

But sometimes it is not good idea to replace it because system may need older version and it will not work with newer one. I prefer to use python3.9 when I need 3.9 and python3.7 when I really need 3.7.


After adding this repo it will also inform you when there will be newer version 3.9.x


This repo works also in Linux Mint which is based on Ubuntu.

Upvotes: 2

Heliton Martins
Heliton Martins

Reputation: 1221

Install Python normally with the deadsnake PPA:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9

Check if you can access Python:

python3.9 --version

If so, create a symlink to set it as "default":

sudo mv /usr/bin/python /usr/bin/python3.7
sudo ln -s $(which python3.9) /usr/bin/python

Upvotes: 3

Related Questions