This post shows how to manually install OpenJDK on your Ubuntu system. This example uses the latest releases of ubuntu (20.04) and OpenJDK (15.0.1), so if you have any other specific version just replace the version in the commands below and you are OK 👍.
🌟 Step 1
Download your version of OpenJDK from the link below 👇
🌟 Step 2 Create a destination folder for JDK folders and files.
sudo mkdir /usr/lib/java
🌟 Step 3
Extract the downloaded file in the directory created before 👆.
tar -xvf openjdk-15.0.1_linux-x64_bin.tar.gz -C /usr/lib/java
🌟 Step 4
Open the environment variables file in any text editor [vim, gedit, nano, vscode, sublime, ...]. To use gedit type in the terminal.
sudo gedit /etc/environment
🌟 Step 5
In this step, you need two things. 1. Add the following bin folder /usr/lib/java/jdk-15.0.1/
to the PATH variables in the opened file above 👆. The PATH variable should look like this after adding the above text.
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-15.0.1/bin"
Add this environment variable JAVA_HOME="/usr/lib/jvm/jdk-15.0.1"
to the same file. Now, the environment file should look like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-15.0.1/bin" JAVA_HOME="/usr/lib/jvm/jdk-15.0.1"
Save the file and exit.
🌟 Step 6
Run the following commands to inform the system about the java's location.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/jdk-15.0.1/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk-15.0.1/bin/javac" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk-15.0.1/bin/javac" 0
sudo update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/java/jdk-15.0.1/bin/javap" 0
sudo update-alternatives --set java /usr/lib/java/jdk-15.0.1/bin/java
sudo update-alternatives --set javac /usr/lib/java/jdk-15.0.1/bin/javac
sudo update-alternatives --set javap /usr/lib/java/jdk-15.0.1/bin/javap
🌟 Step 7
Now you are done, you need just to verify the installation by typing those commands. The output should be the locations you add before.
update-alternatives --list java
update-alternatives --list javac
update-alternatives --list javap
🌟 Step 8
If anything went wrong in the previous step, just close and reopen the terminal or restart the computer. Otherwise 🎉Congratulations🎉, you are officially installed the OpenJDK.
Top comments (3)
On step 5 when you add bin folder and JAVA_HOME variable you use /usr/lib/jvm/. Should it be /usr/lib/java/ since that's where we extracted our files?
Thank you, your post made installing jdk easy. I will be writing a similar titled post, using jdk-15.0.2. It will be based on this post.
Thank you for your comment and feel free to repost