Install and update Java
There are many flavors of Java and the Java Virtual Machine (JVM) that work with Besu. They might impact performance, start time, and more. Consider the options carefully when installing Java on your host machine. Currently, we recommend Java 21.
Install Java
Download the version of Java you would like to install. If you are running Besu outside a virtual environment, like Docker, you must have Java installed on the host machine.
Download OpenJDK 21.
You can find platform-specific installation instructions with the download. The following installation examples use OpenJDK.
Install Java on Ubuntu
You can install OpenJDK on Ubuntu using the apt-get
command.
-
Ensure
apt
libraries are installed and up-to-date:sudo apt update && sudo apt upgrade -y
-
Confirm whether Java is already installed:
java -version
If a version is returned, and you would like to update, see how to update Java on Ubuntu.
-
If no version is returned, use
apt
to install the preferred version.sudo apt-get install openjdk-21-jdk
-
Confirm the installation:
java -version
-
You might need to update your environment to make Java visible to Besu. Edit the
.bashrc
file in your home directory (or create it if needed) and add the following lines to the end of the file:.bashrcexport JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin -
Save your changes and source the file:
source ~/.bashrc
-
Verify that you updated your environment:
echo $JAVA_HOME
echo $PATHYou should see the JDK versions output.
Install Java on MacOS
You can install OpenJDK on MacOS using Homebrew.
-
With
brew
installed, run:brew install openjdk@21
You can target another version if you prefer.
-
Confirm the installation:
java -version
The OpenJDK version you install should display.
If this command returns
command not found: java
, check your terminal logs. Brew might prompt you to create a symlink or update your path variables within the logs in the terminal output. If so, run the prompts provided.
Update Java
Update Java on Ubuntu
To update Java on Ubuntu, uninstall the current versions and follow the instructions to install Java on Ubuntu with your target version.
If you started with this guide, you can uninstall Java using the following command:
sudo apt-get purge openjdk-\*
Update Java on MacOS
You can update Java on MacOS using Homebrew.
-
List your Homebrew packages:
brew ls
-
To update the JDK version (for example, from 17 to 21), uninstall the old version and reinstall the target version:
brew uninstall openjdk@17
brew install openjdk@21noteIf you installed a version of Java not using Homebrew, it is located at
/Library/Java/JavaVirtualMachines
and can be safely deleted from that directory. -
To update point versions of Java, run the
upgrade
command:brew upgrade openjdk