On this post, I will guide you on installing Java on your development Linux machine. I decided to do this post after getting some questions on how do I manage multiple java versions in my Development environments if I use something to manage it like Sdkman, which I don't, in this post I will explain why.
My preferred development environment is Linux so I'd rather use Linux alternatives to manage java SDK installations as it's built-in in Linux and allow you to manage not only java but any other binaries you want to manage and make accessible in your command line when using Linux. I will guide you to the process of installing Java 11 and running your first Hello World application using it.
The full installation process will be using the command line. So let's start, open a terminal console and
cd to your preferred working directory.
- Make sure to have wget installed.
sudo apt update && sudo apt install wget
- Download openjdk:
Can check for updated java 11 versions here: https://jdk.java.net/java-se-ri/11
- Once download finished, add permissions:
chmod +x openjdk-11+28_linux-x64_bin.tar.gz
- Create folder where jdk will be installed
- Extract it to /usr/lib/jvm/open-jdk-11 folder you have just created.
tar -xzf ./openjdk-11+28_linux-x64_bin.tar.gz -C /usr/lib/jvm/open-jdk-11 --strip-components=1
Update alternatives to add java, javac, jshell and jar
- list installed version
update-alternatives --list java
- configure java installation
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/open-jdk-11/bin/java 1
- configure javac installation
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/open-jdk-11/bin/javac 1
- configure jar installation
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/open-jdk-11/bin/jar 1
- configure jshell installation
sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/open-jdk-11/bin/jshell 1
- Test installation, get java version:
- Test installation using jshell
- Type in
Ctrl + Dto exit.
If you have multiple versions of java installed using this same process above, you can just switch between them using alternatives,
- Display installed versions of java
update-alternatives --display java
- Config the version you want to use:
sudo update-alternatives --config java
You can now pick the option you want from the available list. That's it, you're done and have a working local development java environment ready to go.
If you want to quick start with creating an API in Java using Spring Boot, make sure you have git and maven installed(
sudo apt install git && sudo apt install maven) and check out this Spring Boot Crash Course, it's quite easy and quick to follow.