Explain Codes LogoExplain Codes Logo

How to install JDK 11 under Ubuntu?

java
jdk-installation
ubuntu
java-development
Anton ShumikhinbyAnton Shumikhin·Dec 18, 2024
TLDR

To install OpenJDK 11, run these terminal commands:

  • Bring your packages up-to-date:
sudo apt update
  • Start the actual JDK installation:
sudo apt install openjdk-11-jdk
  • Don't forget to check the version:
java -version

In the output, you should see something referencing to JDK 11.

Setting the primary JDK

When juggling various JDK versions, set OpenJDK 11 as the default:

  • Choose your Java warrior:
sudo update-alternatives --config java
  • Don't neglect the Java compiler:
sudo update-alternatives --config javac

To view the entire line-up of your JDKs:

update-java-alternatives --list

Leveraging SDKMAN! for JDK management

Turn to SDKMAN! to manage multiple Software Development Kits in parallel on Unix systems:

  • Bring SDKMAN into play:
curl -s "https://get.sdkman.io" | bash
  • Ready SDKMAN for action:
source "$HOME/.sdkman/bin/sdkman-init.sh"
  • Let SDKMAN fetch the Java version you want:
sdk install java 11.0.3-zulu
  • Check what your new miniboss can do:
sdk version

Adding new repositories for fresh JDK versions

To get your hands on the latest JDK versions, consider adding new repositories:

  • Add the OpenJDK PPA:
sudo add-apt-repository ppa:openjdk-r/ppa
  • Eagerly fetch the new package details:
sudo apt update

Laying out JAVA_HOME environment variable

Need to launch some applications? The JAVA_HOME environment variable is here to help. Specify the home for your JDK by adding to your .bashrc:

  • Get ready for some coding:
nano ~/.bashrc
  • Declare your new home:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  • Time to put this into action:
source ~/.bashrc

Sorting out potential pitfalls

Encountering installation hiccups? Here’s what might be the culprit:

  • Antique versions: (Buh-bye! 👋 sudo apt remove older JDK versions.)
  • Shoddy network: Good old "Have you tried turning it off and on again?"
  • Permission snags: When your system cries "Sudo, who?", you know what to do!

Balancing multiple JDKs

For power users, wielding different JDK versions might be necessary. Here's why:

  • Development: Even software has its own model catwalk.
  • Stability: Can't let the stable geniuses down!
  • Exploration: Like unchartered waters, but for coders.

Remember, with great power (to switch JDKs), comes great responsibility (to know which version to use).