The problem is due to the download link you are using to download spark:
http://apache.osuosl.org/spark/spark-2.2.1/spark-2.2.1-bin-hadoop2.7.tgz
To download spark without having any problem, you should download it from their archive site (https://archive.apache.org/dist/spark
):
For example the following download link from their archive works fine
https://archive.apache.org/dist/spark/spark-3.0.0/spark-3.0.0-bin-hadoop3.2.tgz
Here is the complete code to install and setup java, spark and pyspark:
# innstall java
!apt-get install openjdk-8-jdk-headless -qq > /dev/null
# install spark (change the version number if needed)
!wget -q https://archive.apache.org/dist/spark/spark-3.0.0/spark-3.0.0-bin-hadoop3.2.tgz
# unzip the spark file to the current folder
!tar xf spark-3.0.0-bin-hadoop3.2.tgz
# set your spark folder to your system path environment.
import os
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
os.environ["SPARK_HOME"] = "/content/spark-3.0.0-bin-hadoop3.2"
# install findspark using pip
!pip install -q findspark
For python users, you should also install pyspark
using the following command.
!pip install pyspark