Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm using WSL how I upgrade Python to the last version through the console?

I'm using WSL how I upgrade Python to the last version through the console?

Right now I have 3.8.10

like image 610
Max Jahleel Castillo Avatar asked Sep 11 '25 19:09

Max Jahleel Castillo


2 Answers

I tried these steps and it worked.

Note: in step 3 you just need to change the version that you want to install

Installation steps

Run the following commands in your WSL terminal:

# Update package lists{
sudo apt update

# Install dependent libraries:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev

# Download Python binary package:
wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz

# Unzip the package:
tar -xzf Python-3.10.8.tgz

# Execute configure script
cd Python-3.10.8
./configure --enable-optimizations

# Build Python 3.10
make -j 2

# Install Python 3.10
sudo make install

# Verify the installation
python3.10

You should see:

Python 3.10.8 (default, october 15 2022, 14:44:10)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

If you want to make Python 3.10 the default that runs when you type python, you can follow these steps:

  1. Change ~/.bashrc file to add the following line:

    alias python='/usr/local/bin/python3.10'
    
  2. And then run the following command to have it take effect in the current shell:

    source ~/.bashrc
    
  3. You can verify it using the python --version command, which should now show:

    Python 3.10.8
    

Originally found in this article.

like image 180
Chami M Avatar answered Sep 14 '25 09:09

Chami M


I'm not sure if others are overthinking it, things have changed in WSL, or my distro (Debian) is well behaved?

I simply ran this, and Python3 went from 3.9 to 3.11:

sudo apt update
sudo apt upgrade

As others have said, due to the way Python changes, this may loose some backward compatibility, but if you're not worried about that this should be fine.

What may have also helped this run smoothly, is I have all of these repos defined:

deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://security.debian.org/debian-security/ bullseye-security main
deb http://ftp.debian.org/debian bullseye-backports main
deb http://ftp.debian.org/debian stable main contrib non-free
like image 35
Stripy42 Avatar answered Sep 14 '25 08:09

Stripy42