I know there is a post with the exact same title but since it’s a little bit outdated I’d like to post a slightly adjusted version for the people who is googling a updated solution.
Step 1: Install Homebrew (if you haven’t done it already)
$ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
Step 2: Update it (if you haven’t done it already)
$ brew update
Step 3: Install Java11
$ brew install java11
Step 4: Symlink it
If you skip this step the system won’t be able to find a java runtime for you to use.