We’ll show you, how to install Python on Linux. Python is an interpreted high-level programming language for general-purpose programming, and at the same time, it is user-friendly. It can be used on many different platforms. Today we will show you how to install the latest version of Python from source on Linux. We are going to use an Ubuntu VPS, but we must point out that the same procedure applies if you have a CentOS. Installing Python on Linux is fairly easy task and should take less then 10 minutes.
Table of Contents
1. Update System Software
First of all, let’s update all your system software to the latest version available. We can do that using the apt package manager that comes with Ubuntu. In case you have a CentOS VPS, you need to use the yum package manager instead.
apt-get update apt-get upgrade
2. Download Python
Once all your system software is up to date you can proceed with the other steps. Initially, let’s download the latest version of Python from the official website in the /opt directory on your server. The latest version of Python at the moment of writing is 3.4.2. Therefore, go ahead and download the gzipped source tarball using the following command:
cd /opt wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
3. Unpack .tgz Package
The download will take less than a minute, so once you download the file, go ahead and unpack it carrying out the following command:
tar -xzvf Python-3.4.2.tgz
4. Install Python on Linux
Now, you are ready to install Python. Enter into the Python-3.4.2/ directory
cd Python-3.4.2
and execute the following commands one by one:
./configure make make altinstall
The installation process usually takes no longer than 5 minutes. Once it is done, you can start using the latest version of Python on your server.
5. Invoke Python
To invoke the Python 3.4.2 interpreter you can run the command:
/usr/bin/python3.4
6. Create a Test Python Script
Now, let’s create a test Python script and execute it using the Python 3.4.2. The script will help you determine the free RAM currently available in your system. Navigate to your /root directory:
cd /root
Create a file:
nano ram
Enter the following code:
#!/usr/bin/python3.4 import os os.system("echo 'Free RAM:'") os.system(" free -m | grep buffers/cache | awk '{print $4}'")
Save the file and make it executable.
chmod a+x ram
Copy the script in some of the directories in your $PATH variable. For example, duplicate it in the /usr/bin/.
cp ram /usr/bin/
Done. As a result, every time you type ‘ram’ in your bash shell, the script will be executed and will display the free RAM available in your system.
root ~ # ram Free RAM: 1277
Of course you don’t have to Install Python on Linux if you use one of our Managed Python Hosting services, in which case you can simply ask our expert Linux admins to install Python on Linux, for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on How to Install Python on Linux, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.