Hey, Tea Lovers! In this post, we will be talking about how to install Apache Flink on Mac OS. It will be a very quick guide We will be installing the latest version of Apache Flink 1.12.1, though it applies to all the versions and possibly any newer one too.
We have other posts on Flink Installation:
Windows: How to Install Apache Flink On Local Windows
Ubuntu: How to Install Apache Flink On Ubuntu
I will be showing two ways, one with the Homebrew, and the other one using the manual download, as we did for the Windows one.
I would be happy to connect with you guys on social media. It’s @coderstea on Twitter, Linkedin, Facebook, Instagram, and YouTube.
Please Subscribe to the newsletter to know about the latest posts from CodersTea.
Requirements to Install Apache Flink on Mac OS
The must-have requirement to install Flink on Mac OS is Java. Be it Java 8 or Java 11. And along with that, you need to make sure that you have the variable JAVA_HOME set.
How to Install Apache Flink On Mac OS via Homebrew
How to Install Homebrew on Mac OS
For the installation using Homebrew, you will need a Homebrew set up on your machine. If it’s not set up in your mac os machine, MacBook or iMac, you can go to Homebrew’s official site Homebrew, and follow the instruction on the page. It would only be to run the following command.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
Code language: JavaScript (javascript)
And this will install the latest Homebrew on your machine.
Now you can check if the Homebrew is installed successfully on the Mac OS by running the following command.
brew -v
alternatively, you can try help
, update
instead of -v
.
Install Apache Flink on Mac OS with Homebrew
Now that we have set up the Homebrew on the Mac OS, we can install the Flink. To install the Apache Flink on Mac OS via Homebrew, you need to run the following command.
brew install apache-flink
Then check if it is installed or not, you can type the version command as follows.
flink --version
For me, it will be a version 1.12.1
, but for you, it may differ. The Apache Flink will be installed on the following path.
/usr/local/Cellar/apache-flink/<your-version-of-flink>/libex
So for me, it is like this
/usr/local/Cellar/apache-flink/1.12.1/libex
I will show how to run the cluster in this post’s last paragraph.
Install Old Stable Apache Flink on Mac OS via Homebrew
To install older releases of the Apache Flink, you can simply add the version number in the command. For example, if you want to install Apache Flink 1.9.1 then you can simply run the following command.
brew install apache-flink@1.9.1
Code language: CSS (css)
Keep in mind that, the given old version may or may not be available. So in such a case, you have to rely on the manual installation as described in the following blocks.
Install Apache Flink on Mac OS Manually
If you don’t want to use Homebrew, no worries, you can always choose the long way. In this case, you can manually download and run Apache Flink on Mac OS.
Download the Apache Flink for Mac OS
I will be installing Apache Flink version 1.2.1 for this post. To get the list of all Flink binaries available to download, head over to this link. Select the version you want to choose and download.
Download Old Stable Apache Flink Release for Mac OS
For the latest release, we can just look in the first paragraph for the link. But for the old release such as Flink Version 1.7.1, you need to select from the old stable release list present on the same page. From the list select the binaries in front of the desired version and then download a binary file that contains -bin-scala_ the name.
I will be selecting Flink Version 1.7.1 for download. and then select the -bin-scala_
file (without Hadoop as I don’t need it)
Now that we have downloaded the Apache Flink binaries, let’s extract the tar file and copy it to a more appropriate location, any location would be fine. For me, it would be,
/Users/imran/Documents/programs/apache-flink/flink-1.12.1
Start and Stop Apache Flink Cluster on Mac OS
Now let us see how to start and stop the Flink cluster on Mac OS, but before let’s create some shortcuts.
Set up Environment Variable for Apache Flink Path
Homebrew and Manual Apache installation use different paths on the machine. To simplify the procedure let’s make an environment variable with the path.
In the file .bash_profile for Bash or .zshrc file for ZSH, you can add the following line.
export FLINK_PATH='Full path of apache Flink'
Code language: JavaScript (javascript)
As I told you earlier, the Homebrew installation path for me is,
/usr/local/Cellar/apache-flink/1.12.1/libex
export FLINK_PATH='/usr/local/Cellar/apache-flink/1.12.1/libex'
Code language: JavaScript (javascript)
and the Manual Download path for me is,
/Users/imran/Documents/programs/apache-flink/flink-1.12.1
export flink_path='/Users/imran/Documents/programs/apache-flink/flink-1.12.1'
Code language: JavaScript (javascript)
Start the Apache Flink Cluster on Mac OS
In the terminal, run the cluster with the following command.
$FLINK_PATH/bin/start-cluster.sh
Code language: PHP (php)
If it is successful then you will see a cluster start to message and the cluster will run in the background.
Then simply go to the localhost:8081 to access the Flink UI Dashboard.
Stop the Apache Flink Cluster on Mac OS
To stop the cluster use the following command.
$FLINK_PATH/bin/stop-cluster.sh
Code language: PHP (php)
Run a Flink Job on Cluster
There are 2 ways you can run a Flink Job on the cluster. UI and via command.
Run Flink Job via Flink Dashboard
The simplest way is to use the UI. First, in the dashboard, go to the Submit New Job page and upload the Jar. Next, select the Jar from the list, and pass the Main class, the argument of the program. Then, submit the job and it will redirect you to the running job page, where you will see the pipelines and their status.
Run a Flink Job via Terminal
The second way is to run it via the Terminal or Command-Line. You can use the following command to run the Flink Job.
$FLINK_PATH/bin/flink run \
--detached \
/path/to/jar/SampleFlinkJob.jar
Code language: PHP (php)
This will run the Flink job in the background. You can then check the status in the Flink Dashboard, on localhost, if it runs successfully.
Conclusion
That’s it for this post. This post is focused on Flink Version 1.12.1 and running it on Mac OS. We looked at both the Homebrew shortcut installation and the Manual installation. Keep in mind to set up the JAVA_HOME properly and make sure the JAVA_HOME path doesn’t contain any space in it.
Check out the post “How to Install Apache Flink On Local Windows“
You can also check out my other post “How to Select Specific Folders or Files As Input in Flink” and the code is on GitHub.
See you in the next post.
HAKUNA MATATA!!!
I would be happy to connect with you guys on social media. It’s @coderstea on Twitter, Linkedin, Facebook, Instagram, and YouTube.
Please Subscribe to the newsletter to know about the latest posts from CodersTea.