Java Development Kit (JDK) is used to develop and test Java applications. It is used by Java developers all around the world. Recently, Oracle JDK 16 was released. A version of Oracle JDK 16 is available for Raspberry Pi as well.
In this article, I will show you how to install Oracle JDK 16 on Raspberry Pi 4. So, let’s get started
Table of Contents
- Requirements
- Downloading Oracle JDK 16 on your Computer
- Copying Open JDK 16 Archive File to Raspberry Pi
- Installing Oracle JDK 16 on Raspberry Pi
- Testing Oracle JDK 16 on Raspberry Pi
- Conclusion
Requirements
Oracle JDK 16 is available for 64-bit ARM processors only. So, you must have a 64-bit operating system installed on your Raspberry Pi for Oracle JDK 16 to work.
We have tutorials on installing some of the most popular 64-bit operating systems on Raspberry Pi 4. You may check them out if you need any assistance on that.
- Ubuntu Server 20.04 LTS: Install Ubuntu Server on Raspberry Pi in Headless Mode and SSH Into It
- Ubuntu Desktop 20.04 LTS: Install Ubuntu Desktop 20.04 LTS on Raspberry Pi 4
- Ubuntu MATE 20.04 LTS: Install Ubuntu MATE 20.04 LTS on Raspberry Pi 4
- Kali Linux: Install Kali Linux on Raspberry Pi 4
- Debian: Install Debian on Raspberry Pi 4
NOTE: I will be using the 64-bit version of the Ubuntu Server 20.04 LTS operating system on my Raspberry Pi 4 for the demonstration. But any one of the 64-bit operating systems mentioned earlier should work just fine.
Downloading Oracle JDK 16 on your Computer
You can download Oracle JDK 16 from the official website of Oracle.
First, visit the official JDK 16 download page from your favorite web browser and click on the Linux ARM 64 Compressed Archive download link (jdk-16.0.1_linux-aarch64_bin.tar.gz) as marked in the screenshot below.
Check the I reviewed and accept the Oracle Technology Network License Agreement for Oracle Java SE checkbox and click on Download jdk-16.0.1_linux-aarch64_bin.tar.gz as marked in the screenshot below.
Select a directory where you want to save the Oracle JDK 16 archive file and click on Save.
Oracle JDK 16 archive file is being downloaded. It may take a while to complete.
At this point, Oracle JDK 16 archive file should be downloaded, as you can see in the screenshot below.
Copying Open JDK 16 Archive File to Raspberry Pi
Once the Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz is downloaded, you have to transfer it to your Raspberry Pi. You can do it via SFTP or using a USB thumb drive. This section will show you how to use the SFTP protocol to transfer the Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz to your Raspberry Pi.
Open a Terminal session on the directory where you have downloaded the Oracle JDK 16 archive file and type in the following command to connect to your Raspberry Pi via the SFTP protocol.
NOTE: Here, ubuntu is the login username, and 192.168.0.106 is the IP address of my Raspberry Pi 4. It will be different for you. So, make sure to replace them with yours.
Type in your login password and press <Enter>.
You should be logged in.
To transfer the Oracle JDK archive file jdk-16.0.1_linux-aarch64_bin.tar.gz on your Raspberry Pi, run the following SFTP command:
The Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz should be transferred to your Raspberry Pi, as you can see in the screenshot below.
Now, close the SFTP session with the following SFTP command:
Installing Oracle JDK 16 on Raspberry Pi
Once you’ve copied the Oracle JDK 16 archive file on your Raspberry Pi, you’re ready to install Oracle JDK 16 on your Raspberry Pi.
First, SSH into your Raspberry Pi as follows:
NOTE: Here, ubuntu is the login username, and 192.168.0.106 is the IP address of my Raspberry Pi 4. It will be different for you. So, make sure to replace them with yours.
Type in your login password and press <Enter>.
You should be logged in to your Raspberry Pi via SSH.
The Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz should be in the HOME directory of your Raspberry Pi, as you can see in the screenshot below.
Extract the Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz in the /opt directory as follows:
Once the Oracle JDK 16 archive file is extracted in the /opt directory, you should see a new directory jdk-16.0.1/ in the /opt directory, as you marked in the screenshot below. Remember the directory name as you will need it very soon.
Now, you have to add Oracle JDK 16 to the PATH of your Raspberry Pi so that you can run access the Oracle JDK 16 commands as usual.
Create a new file jdk16.sh in the /etc/profile.d/ directory using the nano text editor as follows:
Type in the following lines in the jdk16.sh file.
export PATH="$PATH:${JAVA_HOME}/bin"
Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the jdk16.sh file.
Now, restart your Raspberry Pi for the changes to take effect.
Once your Raspberry Pi boots, you should see the /opt/jdk-16.0.1/bin directory added to the PATH shell variable as marked in the screenshot below.
Now, you should be able to access the java, javac, and other JDK commands.
If you print the version of the java and javac commands, it should say that you’re running Java 16, as you can see in the screenshot below.
$ javac -version
Testing Oracle JDK 16 on Raspberry Pi
To test whether you can compile a simple Java program using Oracle JDK 16, create a new Java source file HelloWorld.java as follows:
Type in the following lines of codes in the HelloWorld.java source file.
Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the HelloWorld.java source file.
To compile the HelloWorld.java source file, run the following command:
A new file HelloWorld.class should be generated, as you can see in the screenshot below. It means that the HelloWorld.java source file was successfully compiled.
Once the HelloWorld.java source file is compiled, you can run the HelloWorld program as follows:
As you can see, the HelloWorld program printed the text Hello World! On the screen. So, you can compile and run Java programs using Oracle JDK 16. It’s working just fine.
Conclusion
In this article, I have shown you how to download Oracle JDK 16 for Raspberry Pi. I have also shown you how to install Oracle JDK 16 on your Raspberry Pi. I have shown you how to compile a simple Java program and run it with Oracle JDK 16 on your Raspberry Pi as well.
from Linux Hint https://ift.tt/3iRfCo5
0 Comments