Build Python From Source On Linux
You might want to build Python yourself. It is usually easier to install a binary version or install it from a package manager but there are many reasons to build it yourself. Personally, I feel like it gives me more control and the ability to customize more.
- This will include pip.
- Make sure to swap the version numbers for the latest version.
- Keep in mind that you will probably also have a version of Python installed with your system. Pay attention and don’t get these mixed up.
Go here to find the latest version: https://www.python.org/downloads/source/
Pull it down like this:
Unpack it and cd into the upacked directory like this:
tar xvfz Python-3.9.5.tgz cd Python-3.9.5/
The value of prefix is the directory where it will be installed when you run “make install”. The “make” command builds and the “make install” command installs it. If you specify an install directory that you don’t own ( ex. /opt/Python-3.9.5 ) you will need to use sudo. There are probably other options that you might want to use. Also, you might want to have SSL libraries available before building. You can build it like this.
./configure --prefix=/home/user1/python3 --enable-optimizations make make install
This will give you Python 3 and Pip 3 by default. You can find and run them from here.
You can add this new bin directory to your path with a higher priority than other directories by specifying it first like this:
You can verify that python3 and pip3 now point to the newly installed version and not the version that comes with your system like this.
which python3 which pip3
You should now also be able to run these commands like this.