简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM