DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Install Apache Spark on Ubuntu Linux (Spark 4.2.0 Guide)

Install a supported Java runtime, download and verify Apache Spark 4.2.0, run a local shell, and set up a Standalone cluster on Ubuntu, with security notes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To get a working local Apache Spark 4.2.0 on Ubuntu, install a Java runtime that Spark supports, download a pre-built Spark archive from Apache, extract it, and start a bundled shell in local mode. That setup runs on one machine and needs no cluster. If you mean a multi-machine deployment, the cluster section below covers Spark Standalone and marks where YARN and Kubernetes begin.

Before you start: versions and requirements

Spark 4.2.0 is the release this guide uses, and Apache lists it as released July 14, 2026. Check Apache’s downloads page for the current release before you pin version numbers, and substitute the exact filename it shows for your package.

As an Amazon Associate I earn from qualifying purchases.

  • Java: Spark 4.2.0 runs on Java 17, 21, or 25. Java 25 builds before 25.0.3 are deprecated, so use 25.0.3 or later if you choose Java 25, or pick 17 or 21.
  • Python: Python 3.10 or later, if you plan to use PySpark.
  • Scala: Spark 4 is built with Scala 2.13, and Scala 2.12 support has been dropped. Match your Scala application to 2.13.
  • Ubuntu release and architecture: Java package names differ between Ubuntu releases. Run lsb_release -a and dpkg --print-architecture before installing anything.

Step 1: Install and point JAVA_HOME at a supported JDK

  1. Check whether Java is already present with java -version. If the version is outside the list above, install a supported one alongside it.
  2. Refresh package lists with sudo apt update, then search for the OpenJDK packages your release offers: apt-cache search openjdk.
  3. Install the JDK 17 or 21 package your release lists. On releases that package it, the name is typically openjdk-21-jdk-headless. Use the name the search returned, not a guessed one.
  4. Set JAVA_HOME to the installed JDK so Spark does not depend on whichever java comes first on PATH: export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))). Add that line to ~/.bashrc, open a new terminal, and run java -version again.

If your release does not package a JDK in the supported range, use an official OpenJDK build, unpack it under your home directory, and point JAVA_HOME at it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 2: Download Spark and verify the archive

On Apache’s downloads page, choose release 4.2.0 and a package type. A pre-built package for a Hadoop version is the simpler choice for a local install. The Hadoop-free build suits environments that supply their own Hadoop jars. Download the archive together with its signature and checksum files from the same page.

Apache recommends verifying the release against its published KEYS file before you use it. Import the keys and check the signature, using the filename you downloaded:

  1. Import the KEYS file: gpg --import KEYS
  2. Verify the signature: gpg --verify spark-4.2.0-bin-hadoop3.tgz.asc spark-4.2.0-bin-hadoop3.tgz. Replace the example name with the package you chose.

Follow the checksum step described on the same page if it is provided. Do not extract an archive that fails verification.

Step 3: Extract Spark and set SPARK_HOME

Extract the archive into a directory you manage, then point SPARK_HOME at it and add its bin directory to PATH:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. mkdir -p ~/opt && tar -xzf spark-4.2.0-bin-hadoop3.tgz -C ~/opt
  2. Add these lines to ~/.bashrc, adjusting the directory to match what was extracted:
    export SPARK_HOME=$HOME/opt/spark-4.2.0-bin-hadoop3
    export PATH=$SPARK_HOME/bin:$PATH
  3. Reload the file with source ~/.bashrc.

Step 4: Run Spark locally

Local mode needs Java on PATH or JAVA_HOME set, and no Hadoop cluster. Start from the extracted directory and run the bundled shells with --master "local[2]". The value local uses one worker thread, and local[N] uses N threads:

  1. cd $SPARK_HOME
  2. Scala shell: ./bin/spark-shell --master "local[2]". A scala> prompt means the shell started and created its Spark session.
  3. Python shell: ./bin/pyspark --master "local[2]", which opens a PySpark session.
  4. Bundled example: ./bin/spark-submit examples/src/main/python/pi.py 10. The job prints an estimate of pi and exits.

Apache’s documentation presents these commands as examples. If one fails, the Java check in Step 1 and the PATH setting in Step 3 are the first things to recheck.

Alternative install paths

  • PyPI: pip install pyspark installs PySpark from the Python package index. Java is still required at runtime.
  • Docker: Apache publishes Docker images. Use them when your project already runs in containers, and check your project’s needs before choosing this route.

Choose a deployment: local, Standalone, YARN, or Kubernetes

Local mode is the path above. “Install Spark on a cluster” means choosing one of the cluster managers Spark supports. The table compares the four routes.

Route Use it when Trade-off
Local mode (local or local[N]) Learning, development, and testing on one machine Work runs on a single host; no distributed workers
Spark Standalone You want a Spark-managed cluster on your own machines without another resource manager You manage start scripts, ports, SSH access, and security yourself
YARN You already run a Hadoop YARN cluster Setup depends on your Hadoop environment; follow Apache’s YARN deployment guide
Kubernetes You already run workloads on a Kubernetes platform Requires cluster and container configuration; follow Apache’s Kubernetes deployment guide
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Spark Standalone: set up a multi-node cluster

Standalone is Apache’s simple deployment mode. It can run on one machine for testing or across several nodes. Every node needs the same Spark distribution and a compatible Java runtime, so extract the archive to the same path on each host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start the master

  1. On the master host, run ./sbin/start-master.sh from $SPARK_HOME.
  2. Note the spark://HOST:PORT URL the master prints. The default service port is 7077.
  3. Open the master web UI, which listens on port 8080 by default, and confirm it loads.

Start the workers

  1. On each worker host, run ./sbin/start-worker.sh spark://HOST:7077, replacing the host with the master address you noted.
  2. Return to the master web UI and confirm each worker appears. If it does not, recheck the master URL and port.

Launch workers across hosts with conf/workers

To start all workers from the master, list worker hostnames in conf/workers, one per line. The launch scripts reach each worker over SSH, which needs key-based, passwordless access from the master. Then run ./sbin/start-all.sh on the master.

Submit a job to the cluster

Point spark-submit at the master URL, for example ./bin/spark-submit --master spark://HOST:7077 followed by your application file. Use a Spark and Java version that matches the cluster.

Security before you expose a cluster

Do not treat an open Spark master or web UI as a safe default. Apache’s standalone guide states the point directly:

“Security features like authentication are not enabled by default.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache Software Foundation, Spark Standalone Mode, Spark 4.2.0 documentation.

  • Limit access to the master and worker ports to hosts that need them, and keep the cluster on a trusted private network.
  • Enable RPC authentication with spark.authenticate and follow the deployment security guide before you use an untrusted network.
  • For encryption, Apache’s security guide prefers TLS-based RPC encryption. It requires keys and certificates to be configured first.

Common problems and fixes

  • Shell fails to start or reports the wrong Java: run echo $JAVA_HOME and java -version. Confirm the JDK is 17, 21, or 25.0.3 or later, and open a new terminal after editing ~/.bashrc.
  • spark-shell not found: confirm SPARK_HOME points to the extracted directory and that $SPARK_HOME/bin is on PATH.
  • Worker missing from the master UI: check that the master URL matches the host and port the master printed, that port 7077 is reachable from the worker, and that the worker can resolve the master hostname.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.