skip to Main Content

I had installed homebrew for some tool which was working best when installed with homebrew, so I think from one of the dependencies it installed Java 20 as well so whenever I run java --version or javac --version it gives

openjdk 20 2023-03-21
OpenJDK Runtime Environment Homebrew (build 20)
OpenJDK 64-Bit Server VM Homebrew (build 20, mixed mode, sharing)

When running which java gives following:

/home/linuxbrew/.linuxbrew/bin/java

But when I run sudo update-alternatives --config java I get:

There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/java
Nothing to configure.

So my question is, how can I disable or remove java from homebrew so that I can use the java8 which is required for my project?

2

Answers


  1. You can install the java using below-mentioned command:

    brew uninstall --ignore-dependencies java
    

    To ensure that you are using java 8, you need to add path into bash file(~/.bashrc or ~/.zshrc)

    Command to set path:

    export PATH=/usr/lib/jvm/java-1.8.0-amazon-corretto/bin:$PATH
    

    After that do:

    source (~/.bashrc or ~/.zshrc)
    

    check the java version again. Hope, it helps you.

    Login or Signup to reply.
  2. I think @Maninder gave you the answer you were looking for.

    Later, If you want to use multiple versions of Java, How about using ‘jEenv’? (You may have already tried this method.)

    "jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable".
    This is a greate answer to installing/using jEnv.

    Mac OS X and multiple Java versions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search