Categories Tutorials

Install Python from source on Linux VPS

Python is an open-source high-level programming language 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 your Linux VPS

. We are going to use an Ubuntu VPS, but we must point out that the same procedure applies if you have a CentOS VPS.

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

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

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

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:

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.

To invoke the Python 3.4.2 interpreter you can run the command:


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:


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:

Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to install the latest version of Python for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

admin :