How to install Java using terminal?
The best/safest way to install Java on macOS is with Homebrew; just type this:
brew cask install java

Or if you don’t have Homebrew installed already, just type this command first:
/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;
brew cask install java