Skip to main content

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.

tip

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.

  1. Ensure apt libraries are installed and up-to-date:

    sudo apt update && sudo apt upgrade -y
  2. 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.

  3. If no version is returned, use apt to install the preferred version.

    sudo apt-get install openjdk-21-jdk
  4. Confirm the installation:

    java -version
  5. 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:

    .bashrc
    export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
    export PATH=$PATH:$JAVA_HOME/bin
  6. Save your changes and source the file:

    source ~/.bashrc 
  7. Verify that you updated your environment:

    echo $JAVA_HOME
    echo $PATH

    You should see the JDK versions output.

Install Java on MacOS

You can install OpenJDK on MacOS using Homebrew.

  1. With brew installed, run:

    brew install openjdk@21

    You can target another version if you prefer.

  2. 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.

  1. List your Homebrew packages:

    brew ls
  2. 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@21
    note

    If you installed a version of Java not using Homebrew, it is located at /Library/Java/JavaVirtualMachines and can be safely deleted from that directory.

  3. To update point versions of Java, run the upgrade command:

    brew upgrade openjdk