Installing Latest Version of Python on Ubuntu VPS

PythonInUbuntuVPSFeaturedImage

VPS or a Virtual Private Server is a Hosted Cloud Platform, that lets users use Operating Systems on their Computing Devices, which they haven’t configured in Hard Mode. VPS allows users to use the OS without downloading or installing other software requirements as it is hosted on the web.

If Virtual Network Computing (VNC) is configured in the VPS, the VPS can be accessed in Graphical User Interface (GUI) mode as well. Without VNC, the server can be accessed using SSH using a remote device terminal. You can read how to set up VNC in their Ubuntu, after configuring their server. It can be done by using SSH from a remote device terminal.

But before setting up VNC and accessing the terminal to install Python in Ubuntu, one needs to set up the Ubuntu VPS. VPS is provided by many Cloud Hosting Domains, and they allow users to use Ubuntu VPS at very cheap prices.

Installing Python’s Latest Version in Ubuntu Using GUI

To install the latest version of Python, first, it is needed to update the repositories in Ubuntu’s apt install package. It can be done using the following command in the terminal:

sudo apt update

The output of this command is as follows:

Result Of Sudo Apt Update
Result Of Sudo Apt Update

It should be noted that the Username and IP Address of the VPS has been edited out in the images for security purposes. Now the latest version of Python is being used in Python3.10. It falls under the umbrella of Python3. Hence by using the following command in the Ubuntu terminal, the latest version of Python would be installed.

sudo apt install python3

After installing Python3, its version, and successful installation can be verified using the following command in the Ubuntu terminal:

python3 --version

The –version argument asks the Python3 compiler to produce an output of the version the Python is using. It produces the following output.

Confirmation Of Python Installed In VPS
Confirmation Of Python Installed In VPS

Now, let’s check the working of Python, by running some simple codes. Running the following command in the Ubuntu terminal, opens a Python3 code space that can run and compile Python codes:

python3

Running a simple Hello World code in the code space confirms the successful working of Python. The command python3 is also used to run Python files, that is files ending in .py extension. The following code is run in code space:

print('Hello World')

It produces the following output:

Running First Python Program In VPS
Running First Python Program In VPS

Now, let’s run a Python code from a .py file. A Python file named addition.py is created with the following code, performing basic addition operation in Python:

a=30
b=50
sum=a+b
print(sum)
Contents Of Addition Py
Contents Of addition.py

On running the above code, the sum will be printed out in the terminal. It can be run using the following command in the Ubuntu terminal:

python3 addition.py

It produces the following output:

Running A Py File In Ubuntu VPS
Running A .py File In Ubuntu VPS

In the above image, nano is a file editor in Linux. It is used to edit and save code in Python files. This course covers the basics of Python. All the codes covered in the course can be implemented in the Ubuntu VPS and run using python3 command. Pip can also be installed in Ubuntu VPS. Pip is an important part of Python and it is its Package Installer. All the libraries and modules used in Python are downloaded using Pip, so having Pip in Ubuntu VPS is also important.

Installing Pip in Ubuntu VPS Using GUI

Pip is Python’s package installer. All libraries used in Python can be downloaded from Pip. Pip is also available in different versions, with each version getting an upgrade over previous versions of pip by patching deficiencies in Pip. But before installing it in Ubuntu VPS, one needs to update the Ubuntu Install packages. It is because, after the installation of Python, there would be new packages that need an upgrade before installing any other tool. It can be done by the following command in Ubuntu Terminal:

sudo apt update

It produces the following output, this time:

Apt Update After Installing Python
Apt Update After Installing Python

Installing the latest version of Pip is also necessary. Pip shall also be installed which is supported by the latest version of Python. It can be done by the following command:

sudo apt install python3-pip

It will install pip. Pip can also be confirmed using –version argument as well. Their output is shown in the following images:

Installing Pip In Ubuntu VPS
Installing Pip In Ubuntu VPS
Confirming Pip Version
Confirming Pip Version

It can be confirmed that pip-22.0.2 is the latest version of Pip in Ubuntu Servers. Now to check Pip’s working, lets install Pandas Library using Pip in the Ubuntu Server. It can be done using following command in Ubuntu Terminal:

pip install pandas

The following output is produced confirming pip’s working in Ubuntu VPS:

Installing Pandas Using Pip
Installing Pandas Using Pip

This article covers up basics of Pip in more detail and should be read by beginners for more understanding of the topic.

The VPS can also be accessed using SSH command in remote desktop terminal. Python can be installed using that as well. It is demonstrated in other sections in this article

Installing Python Latest Version Using SSH

The ssh Command in Windows/MacOS terminal allows users to connect to servers through remote desktop over Secure Sockets Layer (SSL). Lets consider a VPS is present at the IP Address of 1.2.3.4 and has a user named ‘kunj’. To access the VPS using SSH command, the following format is used:

ssh {{username}}@{{IPAddress}}

Hence for the above example the command becomes:

On successful connection, the terminal will ask for user’s password. The same steps shall be followed henceforth for installing Python and Pip in The Ubuntu VPS. The following snapshot shows successful connection to Ubuntu VPS through Remote Desktop Terminal:

Accessing VPS Using SSH Command From Remote Desktop
Accessing VPS Using SSH Command From Remote Desktop

The IP Address in the above snapshot has been concealed for Security Purposes. The following steps will be followed for installation of Python’s latest version:

  • Update Installation Repositories
  • Install Python’s latest version using sudo apt
  • Check Python version using –version argument
  • Open code space and run Python code
  • Write a .py file and run it using Python

The updating of Installation repositories would be done by following command:

sudo apt update

It produces the following output:

Apt Update On Ubuntu Terminal Through Remote Desktop
Apt Update On Ubuntu Terminal Through Remote Desktop

Python can be installed using the same command as used above:

sudo apt install python3

And it can be version checked using

python3 --version

It produces the following output:

Confirming Python Install In SSH Terminal
Confirming Python Install In SSH Terminal

python3 acts as a command in Ubuntu terminal and it opens Python code space. It can be opened using:

python3

On opening code space, a simple Python Hello World program can be run to check working of python:

print('Hello World')

The following output is created:

Using Python Code Space In SSH
Using Python Code Space In SSH

Now, lets write a new addition.py file as written above and confirm python3 running the .py file for successful installation. The code in addition.py would be:

a=30
b=50
sum=a+b
print(sum)

The above code prints the sum of 30+50 in the terminal, which has an expected output of 80. It can be seen in the output below:

Running A Py File In Python SSH
Running A Py File In Python SSH

Now that Python runs successfully, lets take a look at installing Pip using SSH Terminal in a Remote Desktop.

Installing Pip in Ubuntu VPS Using SSH

The same steps as in GUI mode will be followed, they are:

  • Updating Installation Repositories
  • Installing Pip using sudo apt install
  • Confirming Pip Version
  • Installing a module using Pip

Using the same command as above, the installation repositories will be updated:

sudo apt update

This update is necessary, as now Python has been installed, there would be new installation modules that need to be updated. On updating, Pip can be installed using the following command:

sudo apt install python3-pip

This produces the following output:

Installing Pip Using SSH 1 1
Installing Pip Using SSH

Pip’s installation can be confirmed by –version argument with pip. pip now acts as a command in Ubuntu Terminal.:

pip --version

It produces the output:

Confirming Pip Version In SSH
Confirming Pip Version In SSH

Now that latest version of Pip has been installed, one can check its working using pip install command. Here the module installed using SSH is pynput module of Python. It can be done by following command:

pip install pynput

The following output is produced:

Installing Pynput Using Pip
Installing Pynput Using Pip

This confirms pip’s working as well. It confirms that accessing Ubuntu VPS through SSH Terminal in Remote Desktop works equally efficiently as using it in GUI mode.

Conclusion

Installing and using Python in Ubuntu Servers is a simple task. One can either use GUI mode or directly access the VPS from the Terminal on a remote desktop using the ssh command. Both of them work equally efficiently. Python3 is the latest Python release and uses Python3.10 or Python3.11. Depends on the release. Both of them can be used for running Python codes efficiently. Once installed, python3 works as a command in Ubuntu Terminal. It opens up a Python codespace wherein Python codes can be run. Python3 also runs Python files or files with .py extensions. Python code is stored in these files and python3 can compile and run them in the terminal.

Pip is an important package installer of Python. It can also be installed in Ubuntu VPS using the apt install command. Pip uses the install command to install Python packages and allows python3 to use them in the code. The –version argument is used to confirm the installation and check the version of the command. Once installed, pip also works as a command in Ubuntu Terminal. pip –version shows the version Pip is using. python3 –version shows the version Python is using.