Skip to content

Setting Up Python on a Linux Server – Start Development & Automation

Learn how to install and update the Python runtime on various Linux distributions to ensure a secure and up-to-date environment → Find out more now

12 November 20262 min read41 Views0 helpful

Introduction

This guide shows you how to install the Python runtime and venv. The commands must be executed via SSH. If you don’t know how to connect to your server via SSH, check out our First Access (SSH) guide.

Preparation

Before installing anything on your server, you should run the update command appropriate for your operating system to keep your server secure and up to date.

Code
  sudo apt update
Code
  sudo yum update
Code
  sudo zypper update
Code
  sudo dnf update

Installation

Most Linux distributions come with Python pre-installed, but the version is often outdated or some packages are missing. You can check if Python is installed (python3 --version) and then use the following commands to install or update the runtime.

Code
  // Check version
  python3 --version

  // Install / update runtime
  sudo apt install python3
Code
  // Check version
  python3 --version

  // Update runtime
  sudo yum install python3
Code
  // Check version
  python3 --version

  // Update runtime
  sudo zypper install python3
Code
  // Check version
  python3 --version

  // Update runtime
  sudo dnf install python3

Running Code

Now that Python is installed on your server, you can start your Python programs.

Interpreter Mode

Use the command python3 to start the Python interpreter. You can enter any valid Python code after the >>> prompt, which will be executed after pressing Enter. Exit the interpreter with exit().

Running .py Files

To run .py Python files, simply use the command python3 [filename].py, replacing [filename] with the path to the desired file.

Tip

Most programs you find online can be started with python3 main.py since main.py is often the entry point of Python programs.

Virtual Environments

When programming with Python, you often need external packages installed via pip. You can install these globally (available to all .py scripts) or isolate them in a virtual environment (venv).

Creating a venv

First, navigate to the folder where you want to set up your venv using cd. Then run python3 -m venv . to install the necessary files in the current directory.

Activating & Deactivating

To run commands like pip install inside the venv, you need to activate it with source /bin/activate. After that, your console will operate only within the venv, and scripts will access only locally installed packages.

When you’re done, exit the venv with the command deactivate.

Conclusion

Congratulations, you have successfully installed and set up Python! If you have any questions or issues, our support team is available daily and happy to help!

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

Connect to your server via SSH, update your system (e.g., sudo apt update), and install Python using sudo apt install python3 (or the equivalent command for yum, zypper, or dnf depending on your distribution).
Use the command python3 --version to check if Python is installed and to see which version is running.
Start the Python interpreter with the command python3. After the >>> prompt, enter valid Python code which runs after pressing Enter. Exit the interpreter with exit().

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.