Today we’re going to talk about something that’s near and dear to my heart installing Python without a GUI. Why would anyone want to do this? Well, let me tell you… because sometimes life gets in the way of your computer screen getting in the way of your computer screen.
You see, there are times when we need to install software on our machines but for some reason or another, we can’t use a graphical user interface (GUI) to do it. Maybe we’re working remotely and don’t have access to a display, maybe we’re using headless servers that don’t have screens at all, or maybe we just prefer the command line for some reason.
Whatever your situation may be, don’t worry bro!! Installing Python without a GUI is actually pretty easy once you know how. Let me walk you through it step by step.
To set the stage open up your terminal (or SSH into your server if you’re working remotely). On most Linux distributions, this can be done by pressing Ctrl + Alt + T on your keyboard or searching for “Terminal” in the application menu. Once you have a terminal window open, let’s get started!
Step 1: Update Your Package Manager
Before we install Python, it’s always a good idea to update our package manager (in this case, apt) so that we can ensure we have access to the latest packages and dependencies. To do this, simply run the following command in your terminal window:
# This script updates the package manager (apt) to ensure access to the latest packages and dependencies.
# Use sudo to run the command as a superuser for necessary permissions.
sudo apt-get update # Update the package manager.
# The command "apt-get update" updates the list of available packages and their versions, but does not install or upgrade any packages.
# This ensures that the latest versions of packages are available for installation.
# The "sudo" command is used to run a command with administrative privileges, allowing the user to make changes to the system.
# The "update" command is used to update the package manager's database of available packages and their versions.
# The "apt-get" command is used to manage packages on Debian-based systems, such as Ubuntu.
# The "sudo apt-get update" command is a common first step before installing new packages or upgrading existing ones.
Step 2: Install Python
Now that our package manager is up to date, let’s install Python! This can be done with a single line of code. Run this command in your terminal window:
# This line uses the sudo command to run the following command as a superuser, allowing for system-wide changes.
sudo apt-get update
# This line uses the apt-get command to install the python3 package.
apt-get install python3
sudo apt-get install -y python3
sudo apt-get update
sudo apt-get install -y python3
That’s it! You should now have Python installed on your machine without ever having to open up a GUI. Pretty cool, huh?
Step 3 (Optional): Verify Your Installation
If you want to make sure that Python was indeed installed correctly, you can run the following command in your terminal window:
# This line is a comment and does not affect the functionality of the script
# It is used to provide information and explanations to the reader
# This line uses the command "python3" to check the version of Python installed on the machine
# The "--version" flag is used to specify that we want to check the version
python3 --version
# This line is a comment and does not affect the functionality of the script
# It is used to provide information and explanations to the reader
# It checks the version of Python installed on the machine without opening a GUI
# In that case, the user can try to install Python again or troubleshoot any errors that may have occurred during the installation process
This will output something like this:
# This script is used to print the version of Python installed on the system.
# The first line is a shebang, which specifies the interpreter to be used to execute the script.
#!/bin/bash
# The following line is a comment, which is used to provide information about the script.
# This line specifies the version of Python to be used.
python_version="3.8.2"
# The following line is a command, which is used to print the value of a variable.
# This line prints the version of Python specified in the previous line.
echo "Python $python_version"
Congratulations! You’ve successfully installed Python without a GUI on Linux. Now go forth and script to your heart’s content!