This guide will show you how you can install Python 3.7 (or any other version) for a single user without using sudo. Note that it will only be available for that user, and can be convenient if you don't want to affect other users on the same machine.
1. Download the source code
First download the source. As I'm writing this guide, the latest version is 3.7.9.
Also, extract the source.
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tar.xz tar -xf Python-3.7.9.tar.xz
2. Install build dependencies
To build python will all its features, we will install the minimum build dependencies, plus some optional once to get features like ssl for python. You can choose to ignore some of these if you want.
sudo apt install -y build-essential libreadline-dev libssl-dev libsqlite3-dev libgdbm-dev libgdbm-compat-dev libbz2-dev tk-dev liblzma-dev libffi-dev
3. Compile the source code
Enter the source directory, and run the commands to build the source. You should replace the home directory with your own user (I used "simen")
cd Python-3.7.9 ./configure --enable-optimizations --prefix=/home/simen/.local make
4. Install it for the user
Finally we will install the compiled binaries for the user. Make sure not to use sudo here, or it will be installed for all users.
In the same directory as before run:
Finally, we have to add the user-specific bin folder to our path, unless it is already.
Check if it's in your path with:
It should look something like, and should start with
If it doesn't include your
.local/bin folder, edit the /home/simen/.bashrc file and add to the top:
It's important that
$HOME/.local/bin is at the beginning of the path, so that it overrides the python3 binary if it installed somewhere else in your system.
Save and close the file.
Log out and log back in to refresh your PATH variable.
5. Test that it works
Now, finally run
You should be running Python 3.7!