How to Set and Check Classpath in Linux

A Classpath is a variable that contains the location of user defined classes in Java. This location is usually useful for Java compilers. In Linux, the classpath can be configured through terminal application, whereas in Windows environment, these values can be changed through environment variables. In this tutorial we will guide you on how to set classpath in linux.


Step#1: Access Classpath

First of all, let’s check for the class path over here, and for that, let’s open up the terminal and type in
echo $ {CLASSPATH}
This command will basically print the linux classpath value in the command prompt. There is no response, and nothing is printed on the screen, which means that no classpath has been currently set in Linux.

display current value of the classpath

Step#2: Update Classpath

To set the classpath, type the command export CLASSPATH=/root/java and enter. By using the export command over here, we can set the class path for Java in a Linux or UNIX environment directly from the command prompt.
Now when we check for the class path, you will see that we have successfully set the classpath in Linux, and that the classpath value is displayed on the screen here.

change the classpath and verify

And that completes this tutorial on how to set classpath in Linux.