View By

Categories

 

Installing Apache Spark and Scala (Mac)

Updated: Sep 19, 2019


In this Spark Scala tutorial you will learn,

  • How to install Apache Spark on Mac OS.

  • By the end of this tutorial you will be able to run Apache Spark with Scala on Mac machine.

  • You will also download Eclispe for Scala IDE.


To install Apache Spark on windows machine visit this.



Installing Homebrew

  1. You will be installing Apache Spark using Homebrew.

  2. So install Homebrew if you don’t have it, visit: https://brew.sh/ and copy paste the command on your terminal and run it.


Installing Apache Spark

  1. Open terminal and type command brew install apache-spark and hit Enter.

  2. Create a log4j.properties file. Type cd /usr/local/Cellar/apache-spark/2.3.1/libexec/conf and hit Enter. Please change the version according to your downloaded version. Spark 2.3.1 is the version installed for me.

  3. Type cp log4j.properties.template log4j.properties and hit Enter.

  4. Edit the log4j.properties file and change the log level from INFO to ERROR on log4j.rootCategory. We are just changing the log level from INFO to ERROR only.




Download Scala IDE

  • Install the Scala IDE from here.


  • Open the IDE once, just to check if it's running fine. You should see panels like this;



Test it out!

  1. Open terminal and go to the directory where apache-spark was installed to (such as cd /usr/local/Cellar/apache-spark/2.3.1/libexec/) and then type ls to get a directory listing.

  2. Look for a text file, like README.md or CHANGES.txt.

  3. Type command spark-shell and hit Enter.

  4. At this point you should see a scala> prompt. If not, double check the steps above.

  5. Type val rdd = sc.textFile("README.md") or whatever text file you’ve found and hit Enter. You have just created a rdd of readme text file. Now type rdd.count() and hit Enter to count the number of lines in text file.

  6. You should get a count of number of lines in that file! Congratulations, you just ran your first Spark program! Don't worry about the commands, I will explain them.




Sample Execution



You’ve got everything set up! If you have any question please don't forget to mention in the comments section below.



Main Menu | Next: Just enough Scala for Spark




Navigation menu

1. Apache Spark and Scala Installation

1.1 Spark installation on Windows​

1.2 Spark installation on Mac

2. Getting Familiar with Scala IDE

2.1 Hello World with Scala IDE​

3. Spark data structure basics

3.1 Spark RDD Transformations and Actions example

4. Spark Shell

4.1 Starting Spark shell with SparkContext example​

5. Reading data files in Spark

5.1 SparkContext Parallelize and read textFile method

5.2 Loading JSON file using Spark Scala

5.3 Loading TEXT file using Spark Scala

5.4 How to convert RDD to dataframe?

6. Writing data files in Spark

​6.1 How to write single CSV file in Spark

7. Spark streaming

7.1 Word count example Scala

7.2 Analyzing Twitter texts

8. Sample Big Data Architecture with Apache Spark

9. What's Artificial Intelligence, Machine Learning, Deep Learning, Predictive Analytics, Data Science?

10. Spark Interview Questions and Answers

1 comment

Write your first blog & earn!!

Home   |   Contact Us

©2019 by Data Nebulae