BlankStacks

blankstacks it a startup website/business for education in computer science and engineering field…

Follow publication

Changing Default Python version in Ubuntu

Every Ubuntu version comes with a default python version. for example: Ubuntu 20 LTS came with Python 3.8.

If you want to use different python version you can do this with update-alternatives.

Ex. If you have a later/newer version of Python like 3.8 and you want to set earlier/older version like 3.7 as default.

Step-1: Check Python version with

python --version

for purpose of this example, I assume you have python 3.8 installed in you system.

Step-2: Install the python version to set as default.

sudo apt-get install python3.7

Step-3: run the update-alternatives command to add both python version in alternatives. and set higher priority to desire version.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 10

Now, Because we set the higher priority to python 3.7, it is the default python version now, but you can see and change the version as you need by this command.

sudo update-alternatives --config python

If Something went Wrong!

In some cases (e.g., installing or updating certain packages), you’ll get an error message if you’ve run the commands above. To update these packages, you’ll have to temporarily undo these changes. Here’s how to do that:

  1. Remove all alternatives.
sudo update-alternatives --remove-all python

2. Set things as they are before.

sudo ln -s python3.8 /usr/bin/python

Setup again

Once you’re done updating these packages, execute the commands at the top to set python3.7 as the default again.

Hi, I’m Dilip Singh, a computer science student, if you want to say or share anything with me about my post and if anything not working find me on

Twitter , GitHub , LinkedIn

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

BlankStacks
BlankStacks

Published in BlankStacks

blankstacks it a startup website/business for education in computer science and engineering field. providing the best content for learning computer science, machine learning, data science etc.

Dilip Singh
Dilip Singh

Written by Dilip Singh

0 Followers

Computer Science Student interested in Machine Learning

No responses yet

Write a response