How to Install Oracle Java JDK 16 on Raspberry Pi

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

  1. Requirements
  2. Downloading Oracle JDK 16 on your Computer
  3. Copying Open JDK 16 Archive File to Raspberry Pi
  4. Installing Oracle JDK 16 on Raspberry Pi
  5. Testing Oracle JDK 16 on Raspberry Pi
  6. 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.

  1. Ubuntu Server 20.04 LTS: Install Ubuntu Server on Raspberry Pi in Headless Mode and SSH Into It
  2. Ubuntu Desktop 20.04 LTS: Install Ubuntu Desktop 20.04 LTS on Raspberry Pi 4
  3. Ubuntu MATE 20.04 LTS: Install Ubuntu MATE 20.04 LTS on Raspberry Pi 4
  4. Kali Linux: Install Kali Linux on Raspberry Pi 4
  5. 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.

$ sftp ubuntu@192.168.0.106

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:

sftp> put jdk-16.0.1_linux-aarch64_bin.tar.gz

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:

sftp> exit

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:

$ ssh ubuntu@192.168.0.106

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.

$ ls -lh

Extract the Oracle JDK 16 archive file jdk-16.0.1_linux-aarch64_bin.tar.gz in the /opt directory as follows:

$ sudo tar -xzf jdk-16.0.1_linux-aarch64_bin.tar.gz -C /opt

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.

$ ls -lh /opt

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:

$ sudo nano /etc/profile.d/jdk16.sh

Type in the following lines in the jdk16.sh file.

export JAVA_HOME="/opt/jdk-16.0.1"
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.

$ sudo reboot

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.

$ echo $PATH

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.

$ java -version
$ 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:

$ nano HelloWorld.java

Type in the following lines of codes in the HelloWorld.java source file.

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

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:

$ javac HelloWorld.java

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.

$ ls -lh

Once the HelloWorld.java source file is compiled, you can run the HelloWorld program as follows:

$ java HelloWorld

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

Post a Comment

0 Comments