Featured Article

Install PySpark on Linux: Step-by-Step Guide

Kenneth Jul 13, 2026

Installing PySpark on Linux is a straightforward process that allows you to leverage the power of Apache Spark with Python. PySpark is a gateway to distributed data processing, machine learning, and graph computation. Let's dive into a step-by-step guide to ensure a hassle-free installation.

How to Install PySpark on Ubuntu 22.04
How to Install PySpark on Ubuntu 22.04

Before we get started, ensure your Linux distribution is up-to-date, and you have the necessary permissions to install software. Here, we'll use Ubuntu as an example, but the process is similar for other distributions like CentOS or Debian.

Pixel Tool
Pixel Tool

Setting Up Prerequisites

The primary prerequisites for installing PySpark are Java and Scala, as they are required by Spark. We'll use the OpenJDK version of Java and the Scala toolchain for this installation.

the linux file perissions explanation is shown in this diagram, which shows how to use
the linux file perissions explanation is shown in this diagram, which shows how to use

First, let's update your package lists and install the necessary build tools:

Install Java

Linux Basics for Beginners 2026 | Complete Starter Guide
Linux Basics for Beginners 2026 | Complete Starter Guide

OpenJDK 11 is the latest LTS release and is compatible with Spark 3.x. To install it, use the following commands:

```bash sudo apt update sudo apt install openjdk-11-jdk ```

Install Scala

Spark requires Scala 2.12 or 2.13. You can install Scala using SDKMAN!, a tool that helps manage multiple versions of multiple languages. First, install SDKMAN! itself:

🖥️
🖥️

```bash curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" ```

Then, install Scala 2.13:

```bash sdk install scala 2.13.3 ```

Verify the installation by checking the Scala version:

```bash scala --version ```

Installing Apache Spark

the popular linux server software is shown in this graphic above it's main features
the popular linux server software is shown in this graphic above it's main features

Now that we have the prerequisites set up, we'll install Apache Spark. We'll use the official Spark packages, which provide pre-built binaries.

Choose the version of Spark you want to install (3.x for this guide) and download the package. For example, to download Spark 3.1.2, use:

Learn Linux from Beginner to Advanced (Part 23) – File Search Advanced
Learn Linux from Beginner to Advanced (Part 23) – File Search Advanced
a pink box with an arch linux logo on it
a pink box with an arch linux logo on it
I3wm customization with pywal and picom
I3wm customization with pywal and picom
a black and white poster with the words linux on it
a black and white poster with the words linux on it
Different Linux Distributions Explained (Beginner Guide)🚀
Different Linux Distributions Explained (Beginner Guide)🚀
@CIHPERLORDX spy 🕵️🚀
@CIHPERLORDX spy 🕵️🚀
the linux file system is shown in this poster, which shows how to use it
the linux file system is shown in this poster, which shows how to use it
Linux File System Explained – Complete FHS Directory Guide
Linux File System Explained – Complete FHS Directory Guide
the diagram shows how linux works
the diagram shows how linux works

```bash wget "https://dlcdn.apache.org/spark/spark-3.1.2/spark-3.1.2-bin-hadoop3.2.tgz" ```

Extract the Spark Package

Extract the downloaded package using the following command:

```bash tar -xvf spark-3.1.2-bin-hadoop3.2.tgz ```

Then, create a symbolic link to the Spark directory for easy access:

```bash sudo mkdir -p /opt/spark sudo ln -s ~/Downloads/spark-3.1.2-bin-hadoop3.2 /opt/spark/latest ```

Set Environment Variables

To make life easier, let's set some environment variables:

```bash export SPARK_HOME=/opt/spark/latest export PATH=$SPARK_HOME/bin:$PATH ```

You can add these lines to your `~/.bashrc` file to make them persistent across reboots.

Installing PySpark

With Spark installed, we can now proceed to install PySpark. PySpark is available via PyPI, so we can use pip to install it.

First, ensure you have Python 3 and pip installed on your system. Then, install PySpark using:

```bash pip install pyspark ```

Verifying the Installation

To verify that PySpark was installed correctly, create a simple Python script (e.g., `test_pyspark.py`) with the following content:

```python from pyspark import SparkContext sc = SparkContext("local", "First PySpark App") print("Hello, PySpark!") ```

Run the script using `python test_pyspark.py`, and you should see "Hello, PySpark!" printed in your terminal.

Congratulations! You have successfully installed PySpark on your Linux system. You're now ready to dive into the world of distributed data processing and machine learning. Happy coding!