Gradle reports the $JAVA_HOME as incorrect

I am currently in the process of installing Gradle and JAVA on my computer, which I recently upgraded to 19.04. Gradle is reporting that the $JAVA_HOME is incorrect.

I started out by following these instructions to install java I also referred to exercism’s instructions for installing java and gradle, though they appear to be out of date.

I ran sudo apt install default-jdk and then set $JAVA_HOME in /etc/environment and ~/.bash_profile, like so: JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 Next, I installed gradle with apt, sudo apt install gradle. I also updated the PATH with export PATH=$PATH:/opt/gradle/gradle-5.4.1/bin.

When I ran gradle test in my project, it gave me this error. ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-11-openjdk-amd64/bin/. I found this stack overflow error that suggested it could be a problem with the gradle install from apt. I then uninstalled the gradle install from apt using sudo apt-get purge --auto-remove gradle and decided to follow gradle documentation.

Referring to, I downloaded the binary and unzipped it in /opt/gradle. I then added gradle to my PATH variable.

Then I tried running gradle test and got the same error again.
`gradle -v

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-11-openjdk-amd64/bin/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

How can I install gradle on ubuntu 19.04 and get around this error?