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 · Use the -Djava.class.path system property: 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.
🌐
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.
🌐
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
Now to check the value of Java classpath in windows type "echo %CLASSPATH" in your DOS command prompt and it will show you the value of the directory which is included in CLASSPATH.
🌐
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 ...
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
This section explains how to use the PATH and CLASSPATH environment variables on Microsoft Windows, Solaris, and Linux. Consult the installation instructions included with your installation of the Java Development Kit (JDK) software bundle for current information. After installing the software, the JDK directory will have the structure shown ...
🌐
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:
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › java – set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS.
Find elsewhere
🌐
Droidrant
droidrant.com › home › how do i find the classpath in linux?
How Do I Find the Classpath in Linux? [Answered 2026]- Droidrant
July 15, 2022 - To find the classpath on your computer, ... this variable may have other names, including “Classpath.” In Linux and Ubuntu, you can use the command echo %CLASSPATH to find the classpath value....
🌐
Michigan State University
web.pa.msu.edu › reference › jdk-1.2.2-docs › tooldocs › solaris › classpath-linux.html
Setting the class path
The 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. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value. ... A command-line tool, such as java, javac, or javadoc.
🌐
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
🌐
How to do in Java
howtodoinjava.com › home › java basics › java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - If CLASSPATH is not set you will ... or Linux) console or simply %CLASSPATH% printed in the windows command prompt. Happy Learning !! ... There is a subtle but serious bug in the code outlined in section 3 that can be instructive to understanding that classpath is where JVM looks for all classes and not just for dependant classes. The first statement “$ javac –classpath ...
🌐
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
🌐
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.
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › set-java-classpath-on-linux-914077
set java classpath on linux
November 17, 2011 - Hello! I'm a new user in Linux. I'm using opensuse 11.2, but i don't know how to set path to java. The problem in console: Code: Exception in thread &q
🌐
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 .
🌐
Coderanch
coderanch.com › t › 635651 › java › Classpath-Linux-RedHat
Classpath in Linux RedHat (Java in General forum at Coderanch)
How to check if path is set or not. Type echo $CLASSPATH Note - if you are using the '-classpath' you should not need to set the CLASSPATH environment variable since '-classpath' overrides CLASSPATH. ... Hi, Thank you for response. i checked echo $CLASSPATH. Its showing jar files.