8

I have been following these instructions to install the latest java jdk:

www.lonecpluspluscoder.com/2017/04/27/installing-java-8-jdk-os-x-using-homebrew/

brew cask install java

This works great, but when a new version comes out, how do I make sure I can upgrade to that version and ensure that old versions of the jdk are not sitting around on my system?

Rolando
  • 58,640
  • 98
  • 266
  • 407

5 Answers5

14

Warning: Calling brew cask reinstall is deprecated! Use brew reinstall instead

brew reinstall java

roosheee
  • 141
  • 1
  • 2
9
brew cask reinstall java

This command will uninstall old version of jdk and install the latest version

Ce7
  • 340
  • 5
  • 10
  • It fails with `Error: Unknown command: cask` – Boris Jan 05 '22 at 10:24
  • 2
    @Boris This is due to the fact that `brew cask` is no longer a `brew` command. Use `brew --cask` instead. If that doesn't work you may also try just 'brew reinstall java' – Drew Pesall Jun 02 '22 at 13:50
8

By default, Homebrew does not uninstall old versions of a formula, so over time you will accumulate old versions.

The cleanup - brew cleanup command will remove outdated installed package versions.

Daniel Taub
  • 5,133
  • 7
  • 42
  • 72
  • Just to clarify, so whenever I discover a new version, I should run brew cask update followed by a brew cleanup? – Rolando May 31 '17 at 04:11
2

To upgrade the sub-version of java i.e from 11.0.8,10 to 11.0.9.1,1, use the following command.

brew upgrade --cask adoptopenjdk11
Sunil
  • 429
  • 1
  • 9
  • 25
0

As of April 2023,

Install java (openjdk) using brew install openjdk

Then while you have openjdk installed, running brew install openjdk in the future, upgrades java to the latest openjdk version (provided by homebrew).

g7p
  • 116
  • 5