Skip to content
Follow
Ubuntu Linux

How to Install Apache Spark on Ubuntu Linux

Richard
Written by
Richard
Feb 13, 2021 Updated Jul 14, 2026 3 min read
How to Install VMware Workstation Player on Ubuntu Linux
How to Install VMware Workstation Player on Ubuntu Linux

Installing Apache Spark on Ubuntu Linux lets you process and analyze massive amounts of data quickly across multiple computers.

Apache Spark is a free tool for handling big data problems. It’s built to work on many machines at once, making big jobs finish much faster.

This guide shows you how to install Spark version 3.5.1 on Ubuntu 22.04 or 20.04. You’ll get Spark ready for big data projects, helping you with tough data science tasks on your computer.

⚡ Quick Answer

Install Java JDK and Scala using `sudo apt install default-jdk scala`. Download and extract Spark from its official site, then move it to `/opt/spark`. Set `SPARK_HOME` and update your PATH in `~/.bashrc`. Finally, start Spark with `start-master.sh` and `start-slave.sh`.

Install Java JDK

Installing Java JDK is the first step to get Apache Spark running on Ubuntu. Spark requires this program to function correctly. The default Java Development Kit can be installed by running two commands in your terminal: one to update your software list, and another to install Java.

🐧Bash / Shell
sudo apt update
sudo apt install default-jdk

After installing, run the commands below to verify the version of Java installed.

💻Code
java --version

This should show lines like the ones below:

💻Code
openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Install Scala

To install Scala on Ubuntu for Apache Spark, use your system’s software manager. Scala is another important piece that Apache Spark needs to function correctly. A single command installs Scala, after which you can check its version.

🐧Bash / Shell
sudo apt install scala

To verify the version of Scala installed, run the commands below:

💻Code
scala -version

This should display a line like this:

With Java and Scala installed, Apache Spark installation on Ubuntu can begin. This guide details downloading the latest Apache Spark package, version 3.4.1, and placing it correctly on your computer. Follow these steps to download and extract the necessary files for the Apache Spark installation.

Download the latest version of Spark.

Command Prompt
cd /tmp
wget https://archive.apache.org/dist/spark/spark-2.4.6/spark-2.4.6-bin-hadoop2.7.tgz

Then, extract the downloaded file and move it to the /opt directory.

🐧Bash / Shell
tar -xvzf spark-2.4.6-bin-hadoop2.7.tgz
sudo mv spark-2.4.6-bin-hadoop2.7 /opt/spark
⚠️Warning
After that, create the necessary environment variables to run Spark.
💻Code
nano ~/.bashrc

Add the following lines to the bottom of the file and save.

💻Code
export SPARK_HOME=/opt/spark
export PATH=$PATH:$SPARK_HOME/bin:$SPARK_HOME/sbin

Finally, apply your environment changes by running these commands.

After installing Apache Spark on Ubuntu, starting the master process requires one command, and the worker process requires a second. Once both the Spark master and worker processes are running, you can check Spark’s status in your web browser.

💻Code
start-master.sh

Next, start the Spark work process by running the commands below.

💻Code
start-slave.sh spark://localhost:7077

`localhost` can be swapped with your server’s hostname or IP address. When the process starts, open your browser and navigate to the server hostname or IP address.

To connect to Apache Spark using its command shell, execute the following commands. This connection allows you to interact directly with the Spark cluster, enabling data processing and analysis tasks.

💻Code
spark-shell

The commands above will launch Spark Shell.

💻Code
Spark session available as 'spark'.
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _ / _ / _ `/ __/  '_/
   /___/ .__/_,_/_/ /_/_   version 2.4.6
      /_/
         
Using Scala version 2.11.12 (OpenJDK 64-Bit Server VM, Java 11.0.10)
Type in expressions to have them evaluated.
Type :help for more information.

scala> 

That should do it!

Conclusion:

This post covered installing Apache Spark on Ubuntu 20.04 | 18.04. If you find any error above, please use the form below to report.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install LAMP on Ubuntu Linux
Ubuntu Linux How to Install LAMP on Ubuntu Linux
How to Set Up Environment Variables in Windows 11
Windows How to Set Up Environment Variables in Windows 11
How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

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