I think you should not put any paths that a local to your home directory in a system wide file. I would leave /etc/environment well alone, unless you provide some changes, that are necessary or beneficial to all users. Put any changes to the CLASSPATH in your .bashrc in your home directory.

  CLASSPATH=$CLASSPATH:/home/foo:/home/foo/Java_code/my_code
  export CLASSPATH

This way you can source it and any newly started bash will have the settings right at once.

Answer from Mithrandir on Stack Overflow
🌐
Chilkat
chilkatsoft.com › java-classpath-Linux.asp
Java JAR Archives and classpath on Linux
javac -classpath ".:/chilkatJava/chilkat.jar" Test.java java -classpath ".:/chilkatJava/chilkat.jar" Test ... javac -Djava.class.path=.:/chilkatJava/chilkat.jar Test.java java -Djava.class.path=.:/chilkatJava/chilkat.jar Test · IMPORTANT:On Windows systems, the semicolon character should be used for the path separator. However, on Linux systems, the colon character should be used. Privacy Statement. Copyright Chilkat Software, Inc.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. This section explains how to use the PATH and CLASSPATH environment variables on Microsoft Windows, Solaris, and Linux.
🌐
HowTech
howtech.tv › home › how to set and check classpath in linux
How to Set and Check Classpath in Linux - HowTech
September 6, 2013 - 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 ...
🌐
Blogger
javarevisited.blogspot.com › 2011 › 01 › how-classpath-work-in-java.html
How to Set Classpath for Java on Windows and Linux? Steps and Example
I hope you find this Java Classpath ... to set the classpath for java" and I would be happy to answer :) keep learning. Your suggestions and comments are always welcome. If you like to read UNIX command tips you may find 10 tips for using the find command in Linux, 10 tips to increase ...
🌐
Medium
medium.datadriveninvestor.com › java-classpath-know-it-and-use-it-correctly-2cf6e4dc87ee
Java Classpath, know it, and use it correctly! | by Tom Henricksen | DataDrivenInvestor
June 29, 2022 - The CLASSPATH helps the Java Virtual Machine or JVM know where to look for resources. The PATH is geared toward the operating system. If you are on Windows it needs to know where to look for the file or application you are running. The same goes for your Mac or Linux computer.
🌐
YouTube
youtube.com › watch
How to Set and Check Classpath in Linux - YouTube
Follow this easy step by step tutorial to learn about classpath and how to set classpath in Linux.Don't forget to check out our site http://howtech.tv/ for m...
Published   August 3, 2013
🌐
Baeldung
baeldung.com › home › java › core java › java classpath syntax in linux vs. windows
Java Classpath Syntax in Linux vs. Windows | Baeldung
January 8, 2024 - However, if we take a closer look at the Java man page on Linux, it says the classpath separator is the semicolon (;). For example, the man page of the java command from the latest(ver.17) OpenJDK shows: –class-path classpath, -classpath classpath, or -cp classpath A semicolon (;) separated list of directories, JAR archives, and ZIP archives to search for class files. … · Also, we can find the exact text in the Oracle JDK‘s manual.
Find elsewhere
🌐
Michigan State University
web.pa.msu.edu › reference › jdk-1.2.2-docs › tooldocs › solaris › classpath-linux.html
Setting the class path
For example, to use a class library ... /java/MyClasses as well as classes in /java/OtherClasses, you would set the class path to: % java -classpath /java/MyClasses:/java/OtherClasses ......
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › unix › classpath.html
2 Setting the Class Path
April 21, 2026 - The class path is the path that the Java Runtime Environment (JRE) searches for classes and other resource files. ... The class search path (class path) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable.
🌐
Controlyourmindset
controlyourmindset.com › posts › 4403d9aeedd46575525ee48843dcb4f6
How do I find the Java classpath in Linux? – Control Your Mindset
By using the export command over ... 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.
🌐
Coderanch
coderanch.com › t › 612449 › os › Java-CLASSPATH-linux
Java CLASSPATH on linux (GNU/Linux forum at Coderanch)
For User level . Edit the /etc/bashrc ( or the /etc/profile ) and export the java path at the top of the file as follows Save and close . Now the user for which you have set the variable needs to logout and log back in so that the bashrc file will re-execute for that session.
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › java – set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Use set CLASSPATH command initially, and then run Java application or tool in the same command line window. “ It will search the classes/resources in mentioned classpath locations.
🌐
IBM
ibm.com › docs › SSLTBW_2.2.0 › com.ibm.zos.v2r2.ioaz100 › classlin.htm
To define the CLASSPATH environment variable for Linux
January 20, 2022 - Get assistance for the IBM products, services and software you own · Provides fixes and updates for your system's software, hardware, and operating system
🌐
Blogger
javarevisited.blogspot.com › 2011 › 01 › how-classpath-work-in-java.html
Javarevisited: How to Set Classpath for Java on Windows and Linux? Steps and Example
In this Java tutorial, we will learn What is Classpath in Java, how Java resolves classpath and how Classpath works in Java alongside How to set the classpath for Java in Windows and UNIX environment. I have experience in the finance and insurance domain and Java is heavily used in this domain for writing sophisticated Equity, Fixed income trading applications. Most of these investment banks have written tests as part of their core Java interview questions and I always find at least one question related to CLASSPATH in Java on those interviews.
🌐
Coderanch
coderanch.com › t › 635651 › java › Classpath-Linux-RedHat
Classpath in Linux RedHat (Java in General forum at Coderanch)
I tried in linux Terminal to set classpath using command export CLASSPATH = "/lib/mail.jar" . But is it is throwing "Not a Valid identifier". That is caused by the space between 'CLASSPATH' and '='. and also i will provide windows environment its working fine. Window : java -Djava.security.policy=".\java.POLICY" -classpath ".\lib\mail.jar";".\lib\activation.jar"; mail.MailServer Can anyone convert to linux environment.?
🌐
sqlpey
sqlpey.com › java › java-classpath-explained
Java Classpath Explained: Finding Your Classes and Libraries …
July 22, 2025 - Build tools like Maven and Gradle automate classpath management by defining project dependencies in configuration files. These tools handle downloading libraries, compiling code, and creating executable JARs, significantly simplifying the process. ANS: The Java classpath specifies the locations where the Java Virtual Machine (JVM) searches for compiled class files and other resources required to run a Java application. ANS: Use the appropriate separator: a colon (:) on Linux/macOS and a semicolon (;) on Windows, to separate each directory and JAR file path in the classpath list.