I use fish shell and VSCodium (a fork of VS Code without telemetry).
brew install fish
fish
. Optionally, you can set fish as your default shell on macOSbrew install openjdk
brew info openjdk
):For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
fish_add_path /opt/homebrew/opt/openjdk/bin
For compilers to find openjdk you may need to set:
set -gx CPPFLAGS "-I/opt/homebrew/opt/openjdk/include"
fish_add_path /opt/homebrew/opt/openjdk/bin
to be able to run javac
/usr/libexec/java_home -V
to get the JAVA_HOME
of the installed jdks. Mine returns:Matching Java Virtual Machines (1):
21.0.2 (arm64) "Homebrew" - "OpenJDK 21.0.2" /opt/homebrew/Cellar/openjdk/21.0.2/libexec/openjdk.jdk/Contents/Home
/opt/homebrew/Cellar/openjdk/21.0.2/libexec/openjdk.jdk/Contents/Home
JAVA_HOME
environment variable, run set -Ux JAVA_HOME /opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
. You can check this is a symlink to the installed jdk with ls -lart /opt/homebrew/opt/openjdk
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
javac Hello.java
which will create a file called Hellow.class
. Then you can run java Hello
to run your new class (beware this command takes the class name, not the filename). The output of the command is Hello, World!
brew install vscodium
(or visual-studio-code
if you prefer)codium .
. Search for extensions in VSCodium and install Extension Pack for Java which installs several convenient extensions for working with Java. I started with Language Support for Java™ by Red Hat but it misses some functionality, so my recommendation is to go for the extension packbrew install maven