Install Python on Ubuntu 22.10

Written by Peter Steele

April 22, 2023

Categories: Python
Install Python Ubuntu 22.10

Introduction

Hello everyone, today we are going to look at installing Python on Ubuntu 22.10, but this will also apply to any version of Ubuntu that uses the apt-get package management system. To get started, you are first going to need to open up your terminal. The shortcut for this is Ctrl + Alt + T. Once the terminal is open then you need to install the version of Python that you would like. 

By default, any newer version of Ubuntu is going to come pre-installed with Python 3. This will usually be one of the latest versions that are available at the time of the Ubuntu release, but it may be even newer if you have already updated your system packages to the lastest and greatest. 

Install default Python 2/3: 

To get started lets assume you are wanting to install an older version of Python like Python 2. 

Install Python Command

sudo apt-get install python2

Once you press enter, you will see a bunch of package names appear that need to be installed along with a prompt asking if you are sure you wish to install these packages. Type in ‘Y’ and hit enter again for the packages to be installed. Congratulations, you have installed python to your system!

Now if you accidentally deleted Python 3 or corrupted the install somehow, it is the same process to install it to your system, expect instead of python2 you will type python3 like so:

Install Python 3 Command

sudo apt-get install python3

Install any version of Python

As you can see installing python to linux, especially on Ubuntu is rather simple and fast. Of course you can also very easily specify the exact version that you would like to install as well, if you need it for a specific project you are working on. To do so, simply type out the following command:

Install any version of Python

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

Lets break down what these commands are doing and how to use them. The first command is adding a new repository for your system to pull from. Think of a repository as if it were a box that holds all your favorite software inside that you can easily download at any time you wish. In fact you are already using repositories with the installation method of the most recent versions of python, and those just happened to be included by default when you install Ubuntu for you.

Next we are updating the system and packages to make sure everything is properly configured and seen.

Finally we are saying hey, grab this package names python3.5 for me and download it and install it.

Anytime in the future that you need a different version of python, you can now specify the exact version number that you need and you are able to get the version directly in your terminal without having to build python from source or from a wheel file or anything else like that. It really is the easiest solution.

Run Python in the Terminal

Now how do you use the versions of Python that you have installed on the system? Well that is quite simple with the following command:

How to open and use python in the terminal

python2
python3
python3.5

So each command would open a different version of python to use. Just use one command at a time depending on what version you want to launch inside of your terminal. python2 will open the interactive environment in the terminal for the latest version of Python 2 that you have installed. python3 will open the latest version of python3 that you have installed. If you have installed any of the python versions specifically like 3.5 then typing python3.5 will open that version for you.

Of course this is oversimplifying symlinking and how the system knows exactly what you open up, but you need not worry about that right now and just understand the system is able to keep track of your installs if you have installed them like I have indicated above.

Remove Installed Packages

If you ever need to remove a python install, or any package for that matter, it is generally as easy as:

Uninstall package

sudo apt autoremove package-name(python3, python2, etc.)

# example below to remove python2

sudo apt autoremove python2

When you type in this command it will tell you what will be uninstalled and ask you if you are sure. Type ‘Y’ if you want to remove the package from the system or ‘n’ if you do not want to.

Conclusion

So that about wraps up this tutoral. There is an accomanying video tutorial if that is more your speed and is less than 3 minutes long. Hope this tutorial helped to teach you a little about installing packages on Ubuntu and specifically how to install Python and its various versions. 

As always thank you all for your support and helping make this website the success that it is. While your hear, why not check out some of our other tutorials or share them with frends or coworkers? Until next time. 

Related Articles

Why Python?

Why Python?

Introduction Python is one of the most popular programming languages in the world, with a vibrant community of developers and a wide range of applications. It's also an excellent language for beginners who are just starting to learn programming. In this blog post,...

Installing Python on Windows 10/11

Installing Python on Windows 10/11

In this tutorial, we will cover how to properly install Python on Windows 10/11 and how to make sure Python is included in your path. We also cover how to use Python with it’s IDLE and inside of the command prompt.

Python Variable Names

Python Variable Names

Introduction   Python is a powerful programming language, and here at Learn Code Today, it is also one of our favorite to work with! Over the years, Python has jumped to the top of the pack for programming languages over competitors because of its versatility and...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Peter Steele

Peter Steele

Software Engineer/Site Owner

I am a father of 2, happily married and I also love to game! I started this site as a way to pass on what I have learned as a software engineer. Hopefully I can pass on some knowledge to those seeking it and make someone's life just a little better. Happy coding!

Pin It on Pinterest