8/24/2023 0 Comments Multiple python versions linux![]() Luckily, Linux has us covered in this scenario with the update-alternatives command. We want to leave our system default Python installations alone, but we want to develop in Python 3.8. There's a system default Python 2.7, A system default Python 3, and now our newly added Python 3.8. So, we now have a few versions of Python installed on our machine. Managing Alternative Python Installations Ubuntu conveniently makes this the default for us. Once finished, go ahead and verify that the version of Python 3 you wanted is installed on your box: $ python3 -versionĪnd there it is! A shiny new Python: Python 3.8. $ sudo make altinstall Install from source ![]() Luckily for us, Ubuntu allows us to install additional (AKA: alternative) versions of Python by providing us with the make altinstall command: $ cd Python-3.8.0 The frustration of installing Python with apt-get install python3.X is that it'll install Python just fine, but Ubuntu will still default to using whichever version of Python is the default. Installing Alternative Python from Source The latest version of Python is now downloaded. $ sudo tar xzf Python-3.8.0.tgz Download Python The lines below will download a compressed Python 3.9.2 archive to your /opt folder and unzip it: $ cd /opt On your Ubuntu machine, you're going to fetch the Python source from the URL you copied with wget. On that page, scroll to the "files" section and copy the URL of the Gzipped source tarball. The first link on the above page should read Latest Python 3 Release - Python 3.X. The latest version of Python can always be found on the Python Source Releases page on : If a Python version is new enough, some Ubuntu machines might have the updated mirrors necessary to find the latest version More importantly, it's easier to manage multiple Python installations this way. We're going to download and build the latest Python version from source, for a number of reasons. This is where a lot of people might turn to installing Python via Ubuntu's package manager with apt-get install python3.X. ![]() Libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev Install Python dependencies $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ Trust me, it' a required step: $ sudo apt-get install build-essential checkinstall I'm honestly not even sure what half of these do, and neither of us will probably ever need to. Installing Python fresh on a Ubuntu machine requires us to install a whole bunch of prerequisite libraries that Python depends on. The first step should be familiar: we need to update Ubuntu's mirrors and packages to make sure we pull the latest packages when we install anything: $ apt update & apt upgrade -y Obligatory updates ![]() We're going to walk through how to install the current latest version of Python alongside Ubuntu's system Python versions safely and easily. We can easily switch the active version of Python on our machine via a convenient CLI.It's best to avoid messing around with your Python PATH whenever possible.We want to leave our system version of Python intact.So what do we do? There are a couple of ways to go about getting an updated version of Python on Ubuntu, but using Ubuntu's built-in "alternative install" is optimal for a number of reasons: In case nobody has told you not to do that, I'll do the honors: don't do that. But what if you don't want to run either of those versions? If you're like me, you might have tried to replace your system's default installation and destroyed your machine in the process. Code bootcamps and tutorials do a fine job of teaching students how to run Python code locally, but the most meaningful applications don't run on local machines: they run on servers, on the internet, because that's the point, isn't it? Maybe I'm taking crazy pills here.ĭepending on which version of Ubuntu you're running, your VPS probably shipped with either Python 2.7, or both Python 2.7 and Python 3.6. One of my earliest frustrations with Python development had nothing to do with Python itself, but rather the needlessly esoteric act of deploying a Python app. If you're running Ubuntu 18.04 or older, go here. There are a number of subtle differences to managing versions of Python on older distributions of Ubuntu.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |