Installing OpenJDK 15 on Ubuntu 20.04

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

https://jdk.java.net

Step 2 Create a destination folder for JDK folders and files.

sudo mkdir /usr/lib/java 

Enter fullscreen mode Exit fullscreen mode

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 

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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" 

Enter fullscreen mode Exit fullscreen mode

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" 

Enter fullscreen mode Exit fullscreen mode

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 

Enter fullscreen mode Exit fullscreen mode

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk-15.0.1/bin/javac" 0 

Enter fullscreen mode Exit fullscreen mode

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk-15.0.1/bin/javac" 0 

Enter fullscreen mode Exit fullscreen mode

 sudo update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/java/jdk-15.0.1/bin/javap" 0 

Enter fullscreen mode Exit fullscreen mode

 sudo update-alternatives --set java /usr/lib/java/jdk-15.0.1/bin/java 

Enter fullscreen mode Exit fullscreen mode

sudo update-alternatives --set javac /usr/lib/java/jdk-15.0.1/bin/javac 

Enter fullscreen mode Exit fullscreen mode

 sudo update-alternatives --set javap /usr/lib/java/jdk-15.0.1/bin/javap 

Enter fullscreen mode Exit fullscreen mode

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 

Enter fullscreen mode Exit fullscreen mode

update-alternatives --list javac

Enter fullscreen mode Exit fullscreen mode

update-alternatives --list javap 

Enter fullscreen mode Exit fullscreen mode

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.

原文链接:Installing OpenJDK 15 on Ubuntu 20.04

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容