I'm writing this guide for Ubuntu/Debian, for other you need to use their package manager. Here’s a simple way to get Java 17 up and running on Ubuntu:
- Update your package index
sudo apt update
-
Install OpenJDK 17
Ubuntu’s repositories include OpenJDK 17 as
openjdk-17-jdk
. To install both the JRE and JDK:
sudo apt install -y openjdk-17-jdk
- Verify the installation
java -version
You should see output like:
openjdk version "17.0.x" 202x-xx-xx
OpenJDK Runtime Environment (build 17.0.x+xx-Ubuntu-...)
OpenJDK 64-Bit Server VM (build 17.0.x+xx-Ubuntu-..., mixed mode)
-
(Optional) Set
JAVA_HOME
Many tools need theJAVA_HOME
environment variable. First find where Java was installed:
readlink -f /usr/bin/java | sed "s:bin/java::"
That might return, for example, /usr/lib/jvm/java-17-openjdk-amd64/
.
To set it system-wide, edit /etc/environment
:
sudo nano /etc/environment
Add at the end:
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/"
Then reload:
source /etc/environment
echo $JAVA_HOME
- (Alternative) Use SDKMAN! If you need to frequently switch Java versions, to test specific features, the best is to use SDKMAN!. Sdkman is for Java what Nvm(Node version manager) is for node!
Here is how you install it:
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 17.0.8-tem # example build
sdk use java 17.0.8-tem
Now you have to add the source line to .bash_rc, to make sdkman available in any command line:
echo 'source "$HOME/.sdkman/bin/sdkman-init.sh"' >> ~/.bashrc
You can see which java version are available, you can | grep 17
for a specific version(sdk list java | grep 17
):
sdk list java
skdman can be used o install other jvm tools, just use sdk list
to see all the options:
sdk list
The list include( sdk list kotlin
will lost kotlin versions, it's case sensitive ):
- Ant
- Graddle
- Kotlin
- Maven
- Scala