Python Installation without UI

Are you tired of staring at those ***** installation windows every time you want to use your favorite programming language?

Why would anyone want to do that, you ask? Well, for starters, it can be a real time-saver if you need to set up multiple machines or virtual environments with the same configuration. It’s also great for automating your setup process in scripts and CI/CD pipelines.

So without further ado, Let’s roll with our tutorial on Python installation without UI!

Step 1: Choose Your Platform
First things first, you need to decide which platform you want to install Python on. For the purpose of this tutorial, we’ll be using Ubuntu Linux as an example, but the same principles apply for other Unix-based systems like macOS or Red Hat Enterprise Linux (RHEL).

Step 2: Update Your System Packages
Before you start installing Python packages, it’s always a good idea to update your system packages. This ensures that any dependencies required by Python are up-to-date and compatible with the latest version of Python. To do this on Ubuntu Linux, open a terminal window (or SSH into your server) and run:


# Update system packages to ensure compatibility with Python
# Use sudo to run the command as a superuser
# apt-get is a package management tool for Ubuntu Linux
# update is a command to update the list of available packages
# && is a logical operator to run multiple commands in one line
# upgrade is a command to upgrade installed packages to their latest versions
# -y is an option to automatically answer yes to any prompts during the upgrade process
sudo apt-get update && sudo apt-get upgrade -y

Step 3: Install Python Using WGET or CURL
Now that you’ve updated your system packages, it’s time to download the latest version of Python from the official website. You can do this using either wget (which is a command line tool for retrieving files) or curl (a similar tool).

For example, if you want to install Python 3.9 on Ubuntu Linux, run:


# Use sudo to run the command as a superuser with elevated privileges
# wget is a command line tool for retrieving files from a specified URL
# -O specifies the output file name, in this case "Python-3.9.0.tgz"
# The URL is the location of the latest version of Python on the official website
$ sudo wget -O Python-3.9.0.tgz https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz

Or using curl:


# This script uses curl to download a file from a specified URL and save it locally.
# The -O flag tells curl to save the file with the same name as the original file.
# The URL in this script is for downloading the Python 3.9.0 source code.

# Import the curl library and use sudo to run the command as a superuser.
$ sudo curl -O https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
# The -O flag is used to specify the output file name, in this case it will be saved as Python-3.9.0.tgz.
# The URL is the location of the file to be downloaded, in this case it is the Python 3.9.0 source code.
# The .tgz extension indicates that the file is a compressed tar archive.
# The file will be saved in the current working directory.

Step 4: Extract the Python Tarball
Once you’ve downloaded the tarball, extract it using your favorite archiving tool (e.g., tar or unzip). For example, if you used wget to download the tarball, run:


# Use sudo to run the command as a superuser
# Use tar to extract the tarball
# Use -xzf to specify the options for the tar command (x for extract, z for gzip, f for file)
# Specify the name of the tarball to be extracted (Python-3.9.0.tgz)
sudo tar -xzf Python-3.9.0.tgz

Step 5: Configure and Build Python
Now that you’ve extracted the tarball, it’s time to configure and build Python using the provided configuration script (configure). This will generate a customized Makefile based on your system settings. For example, if you used wget or curl to download the tarball, run:


# Change directory to the extracted Python-3.9.0 folder
$ cd Python-3.9.0 

# Run the configure script with superuser privileges to generate a customized Makefile
# The --prefix flag specifies the installation directory for Python
# In this case, it will be installed in /usr/local/python3.9
$ sudo ./configure --prefix=/usr/local/python3.9

Step 6: Build and Install Python
Once you’ve configured Python, it’s time to build and install it using the Makefile that was generated in Step 5. For example, if you used wget or curl to download the tarball, run:


# Use sudo to run the make command with root privileges
# The -j flag specifies the number of jobs to run simultaneously, in this case it is set to the number of processors available on the system
# The $(nproc) command is used to retrieve the number of processors available on the system
# && is used to chain commands, meaning the second command will only run if the first command is successful
# sudo make altinstall will install the built Python version as an alternative to the system's default Python version
sudo make -j$(nproc) && sudo make altinstall

This will compile Python with parallel processing (using nproc to determine the number of CPU cores available on your system), and install it in a separate directory (/usr/local/python3.9) without overwriting any existing versions of Python that you may have installed previously.

Step 7: Verify Your Installation
To verify that Python was successfully installed, run:

# This script checks the version of Python installed on the system

# Use the command "python3.9" to run Python version 3.9
$ python3.9 --version

# The output should display the version of Python installed
# In this case, it should show "Python 3.9.0" as the installed version
Python 3.9.0

Congratulations! You’ve just installed Python without any UI whatsoever. Now you can use your favorite text editor or IDE to write and execute Python scripts on your system, without having to deal with ***** installation windows.

SICORPS