3

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 ?

2
  • 1
    if you don't have it in apt then you can add special repo for Ubuntu deadsnakes Python repo for Ubuntu . And after adding repo you should have all versions in apt Commented Apr 1, 2021 at 15:30
  • 1
    You can install pyenv, then manage Python installations from that Commented Apr 1, 2021 at 15:32

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

6 Comments

sudo apt install python3.9 this doesn't work
This is the error I am getting E: Unable to locate package python3.9 E: Couldn't find any package by glob 'python3.9'
Did you run sudo apt update? If so, maybe it's just not available for 18.04.
Yeah I have done sudo apt update. Still the same
But this doesn't change the default python When I run python --version its still showing 3.7.9
|
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.