Environment variables are global system variables accessible by all the processes/users running under the Operating System [OS], such as Windows, macOS and Linux. Environment variables are useful to store system-wide values, for examples,
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
5: the most frequently-used environment variable, which stores a list of directories to search for executable programs.Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
6: the operating system.Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
7,Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
8: stores the computer and current user name.Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
9: the system root directory.- [Windows]
set VAR_NAME VAR_NAME=VAR_VALUE
0,set VAR_NAME VAR_NAME=VAR_VALUE
1: Current user's home directory.
[Windows] Environment Variables
Environment Variables in Windows are NOT case-sensitive [because the legacy DOS is NOT case-sensitive]. They are typically named in uppercase, with words joined with underscore [
set VAR_NAME VAR_NAME=VAR_VALUE2], e.g.,
set VAR_NAME VAR_NAME=VAR_VALUE3.
Display Environment Variables and their Values
To list ALL the environment variables and their values, start a CMD and issue the command "
set VAR_NAME VAR_NAME=VAR_VALUE4", as follows,
Try issuing a "
set VAR_NAME VAR_NAME=VAR_VALUE4" command on your system, and study the environment variables listed. Pay particular attention to the variable called
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5.
To display a particular variable, use command "
set VAR_NAME VAR_NAME=VAR_VALUE7", or "
set VAR_NAME VAR_NAME=VAR_VALUE8":
// Display a particular variable set COMPUTERNAME COMPUTERNAME=xxxxxx // or, use "echo" command with variable name enclosed within a pair of '%' echo %COMPUTERNAME% COMPUTERNAME=xxxxxx
Set/Unset/Change an Environment Variable for the "Current" CMD Session
To set [or change] a environment variable, use command "
set VAR_NAME VAR_NAME=VAR_VALUE9". There shall be no spaces before and after the
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name0 sign. To unset an environment variable, use "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name1", i.e., set it to an empty string.
set varname set varname=value set varname= set
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
For examples,
An environment variable set via the "
set VAR_NAME VAR_NAME=VAR_VALUE4" command under CMD is a local, available to the current CMD session only. Try setting a variable, re-start CMD and look for the variable.
Using an Environment Variable
To reference a variable in Windows, use
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name3 [with prefix and suffix of
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name4]. For example, you can use the
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name5 command to print the value of a variable in the form "
set VAR_NAME VAR_NAME=VAR_VALUE8".
How to Add or Change an Environment Variable "Permanently"
To add/change an environment variable permanently in Windows [so that it is available to ALL the Windows' processes/users and stayed across boots]:
- Launch "Control Panel"
- "System"
- "Advanced system settings"
- Switch to "Advanced" tab
- "Environment variables"
- Choose "System Variables" [for all users]
- To add a new environment variable:
- Choose "New"
- Enter the variable "Name" and "Value". Instead of typing the "value" and making typo error, I suggest that you use "Browse Directory..." or "Browse File..." button to retrieve the desired directory or file.
- To change an existing environment variable:
- Choose "Edit"
- Enter the new "Value". Instead of typing the "value" and making typo error, I suggest that you use "Browse Directory..." or "Browse File..." button to retrieve the desired directory or file.
You need to RE-START CMD for the new setting to take effect!
To verify the new setting, launch CMD:
set VAR_NAME VAR_NAME=VAR_VALUE
PATH Environment Variable in Windows
When you launch an executable program [with file extension of "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name7", "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name8" or "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name9"] from the CMD shell, Windows searches for the executable program in the current working directory, followed by all the directories listed in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable. If the program cannot be found in these directories, you will get the following error:
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name
To list the current
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5, issue command:
PATH PATH=path1;path1;path3;...
How to Add a Directory to the PATH in Windows
To add a directory to the existing
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 in Windows:
- Launch "Control Panel"
- "System"
- "Advanced system settings"
- Switch to "Advanced" tab
- "Environment variables"
- Under "System Variables" [for all users], select "Path"
- "Edit"
- [For newer Windows 10] A table pops up showing the directories included in the current PATH setting ⇒ "New" ⇒ "Browse..." to select the desired directory to be added to the PATH [Don't type as you will make typo error!] ⇒ Click "Move Up" repeatedly to move it to the top ⇒ "OK" [Don't "Cancel"] ⇒ "OK" ⇒ "OK".
- [For older Windows] If you didn't see a pop-up table, it is time to change your computer.
You need to RE-START CMD for the new PATH setting to take effect!
To verify the new setting, launch CMD:
PATH PATH=path1;path2;path3;...
Notes:
- Windows searches the current directory [
PATH PATH=path1;path1;path3;...
3] before searching theDisplay the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
5 entries. [Unixes/macOS does not search the current directory, unless you include it in the PATH explicitly.] - Windows uses semicolon [
PATH PATH=path1;path1;path3;...
5] as the path separator; while Unixes/macOS uses colon [PATH PATH=path1;path1;path3;...
6]. - If your directory name contains special characters such as space [strongly not recommended], enclosed it with double quotes.
[macOS/Linux] Environment Variables
Environment variables in macOS/Unixes are case-sensitive. Global environment variables [available to ALL processes] are named in uppercase, with words joined with underscore [
set VAR_NAME VAR_NAME=VAR_VALUE2], e.g.,
set VAR_NAME VAR_NAME=VAR_VALUE3. Local variables [available to the current process only] are in lowercase.
Using Environment Variables in Bash Shell
Most of the Unixes [Ubuntu/macOS] use the so-called Bash shell. Under
PATH PATH=path1;path1;path3;...9 shell:
- To list all the environment variables, use the command "
PATH PATH=path1;path2;path3;...
0" [or "PATH PATH=path1;path2;path3;...
1"]. You could also use "set VAR_NAME VAR_NAME=VAR_VALUE
4" to list all the variables, including all local variables. - To reference a variable, use
PATH PATH=path1;path2;path3;...
3, with a prefixPATH PATH=path1;path2;path3;...
4 [Windows uses// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name
3]. - To print the value of a particular variable, use the command "
PATH PATH=path1;path2;path3;...
6". - To set an environment variable, use the command "
PATH PATH=path1;path2;path3;...
7", which sets the variable and exports it to the global environment [available to other processes]. Enclosed the value with double quotes if it contains spaces. - To set a local variable, use the command "
PATH PATH=path1;path2;path3;...
8PATH PATH=path1;path2;path3;...
9" [or "set VAR_NAME VAR_NAME=VAR_VALUE
4PATH PATH=path1;path2;path3;...
8PATH PATH=path1;path2;path3;...
9"]. Local variable is available within this process only. - To unset a local variable, use command "
PATH PATH=path1;path2;path3;...
8export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar
4", i.e., set to empty string [or "export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar
5PATH PATH=path1;path2;path3;...
8"].
How to Set an Environment Variable Permanently in Bash Shell
You can set an environment variable permanently by placing an
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar7 command in your Bash shell's startup script "
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar8" [or
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar9", or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile0"] of your home directory; or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile1" for system-wide operations. Take note that files beginning with dot [
PATH PATH=path1;path1;path3;...3] is hidden by default. To display hidden files, use command "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile3" or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile4".
For example, to add a directory to the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable, add the following line at the end of
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile6" [or
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar9", or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile0"], where
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile9 denotes the home directory of the current user, or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile1" for ALL users.
[For Java] You can set the
abc bash: abc: command not found1 environment variables by adding the following line. For example,
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar
Take note that Bash shell uses colon [
PATH PATH=path1;path1;path3;...6] as the path separator; while windows use semicolon [
PATH PATH=path1;path1;path3;...5].
To refresh the bash shell, issue a "
abc bash: abc: command not found4" command [or re-start the bash shell]:
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile
[Notes] For the older csh [C-shell] and ksh [Korn-shell]
- Use "
PATH PATH=path1;path2;path3;...
1" [or "PATH PATH=path1;path2;path3;...
0"] to list all the environment variables. - Use "
abc bash: abc: command not found
7" and "abc bash: abc: command not found
8" to set and unset an environment variable. - Use "
set VAR_NAME VAR_NAME=VAR_VALUE
9" and "set varname set varname=value set varname= set
00" to set and unset a local variable for the current process.
PATH Environment Variable
Most of the Unixes and macOS use the so-called Bash Shell in the "Terminal". When you launch an executable program [with file permission of executable] in a Bash shell, the system searches the program in ALL the directories listed in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5. If the program cannot be found, you will get the following error:
abc bash: abc: command not found
Take note that the current directory [
PATH PATH=path1;path1;path3;...3] is not searched, unless it is included in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5. To run a program in the current directory, you need to include the current path [
set varname set varname=value set varname= set04], for example,
set varname set varname=value set varname= set0
To list the current
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5, issue command:
set varname set varname=value set varname= set1
How to Add a Directory to the PATH in macOS/Linux
To add a directory to the existing
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 in macOS/Unixes, add the following line at the end of one of the startup scripts, such as
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile6", "
set varname set varname=value set varname= set08"
export CLASSPATH=.:/usr/local/tomcat/lib/servlet-api.jar9", "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile0" [where
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile9 denotes the home directory of the current user] or "
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile1" for ALL users.
To refresh the bash shell, issue a "
abc bash: abc: command not found4" command [or re-start the bash shell]:
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile
To verify the new setting, launch CMD:
set varname set varname=value set varname= set1
Notes:
- Unixes/macOS does not search the current directory [
PATH PATH=path1;path1;path3;...
3], unless you include it explicitly in theDisplay the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
5. In other words, to run a program in the current directory, you need to provide the directory [set varname set varname=value set varname= set
04], for example,set varname set varname=value set varname= set
0You could include the current directory in theDisplay the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
5, by adding this line in a startup script: [Windows searches the current directory [PATH PATH=path1;path1;path3;...
3] automatically before searching the PATH.] - Unixes/macOS uses colon [
PATH PATH=path1;path1;path3;...
6] as the path separator; while Windows uses semicolon [PATH PATH=path1;path1;path3;...
5].
Java Applications and the Environment Variables PATH, CLASSPATH, JAVA_HOME
Many problems in the installation and running of Java applications are caused by incorrect setting of environment variables [global system variables available to all the processes/users running under the Operating System], in particular,
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5,
abc bash: abc: command not found1 and
set VAR_NAME VAR_NAME=VAR_VALUE3.
When you launch a program from the command line, the Operating System uses the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable to search for the program in your local file system. In other words,
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 maintains a list of directories for searching executable programs.
When you launch an executable program [with file extension of "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name7", "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name8" or "
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name9"] from the CMD shell, Windows searches for the executable program in the current working directory, followed by all the directories listed in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable. If the program cannot be found in these directories, you will get the following error:
// [Windows 2000/XP/Vista/7/8/10] "cmd.exe" abc 'abc' is not recognized as an internal or external command, operable program or batch file. // [Windows 95/98] "command.com" abc Bad command or file name
For example, if you are trying to use Java Compiler "
set varname set varname=value set varname= set30" to compile a Java source file, but "
set varname set varname=value set varname= set30" cannot be found in the current directory and all the directories in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5, you will receive the following error:
set varname set varname=value set varname= set6
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 maintains a list of directories. The directories are separated by semicolon [
PATH PATH=path1;path1;path3;...5] in Windows.
For Java applications,
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 must include the following directories:
- JDK's "
set varname set varname=value set varname= set
36" [binary] directory [e.g., "set varname set varname=value set varname= set
37"], which contains JDK programs such as Java Compiler "set varname set varname=value set varname= set
30" and Java Runtime "set varname set varname=value set varname= set
39". - "
set varname set varname=value set varname= set
40" and "set varname set varname=value set varname= set
41" which contain console programs and commands.
The JDK's "
set varname set varname=value set varname= set36" directory should be listed before "
set varname set varname=value set varname= set40" and "
set varname set varname=value set varname= set41" in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5. This is because some older Windows systems provide their own Java runtime [which is often outdated] in these directories [try search for "
set varname set varname=value set varname= set39" in your computer, you may find a few entries].
To add a directory [say JDK's "
set varname set varname=value set varname= set36"] to the existing PATH, check "How to add a directory to the PATH".PATH [For macOS/Linux]
Most of the Unixes and macOS use the so-called Bash Shell in the "Terminal". When you launch an executable program [with file permission of executable] in a Bash shell, the system searches the program in ALL the directories listed in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5. If the program cannot be found, you will get the following error:
abc bash: abc: command not found
For example, if you are trying to use Java Compiler "
set varname set varname=value set varname= set49" to compile a Java source file, but "
set varname set varname=value set varname= set49" can not be found in the list of directories in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5, you will receive the following error:
set varname set varname=value set varname= set8
To support Java applications, you need to include the JDK's "
set varname set varname=value set varname= set36" [binary] directory in the PATH. See "How to add a directory to the PATH".Java Archive [JAR] File
For ease of distribution, Java classes are often archived [zipped] together into a so-called JAR file. To use a third-party Java package, you need to place the distributed JAR file in a location that is available to the Java Compiler and Java Runtime.
How Classes are Found?Java Compiler ["
set varname set varname=value set varname= set49"], Java Runtime ["
set varname set varname=value set varname= set54"] and other Java tools searches for classes used in your program in this order:
- Java platform [bootstrap] classes: include system classes in core packages [
set varname set varname=value set varname= set
55] and extension packages [set varname set varname=value set varname= set
56] in "set varname set varname=value set varname= set
57" [runtime class], "set varname set varname=value set varname= set
58" [internationalization class],set varname set varname=value set varname= set
59,set varname set varname=value set varname= set
60, and others. - Java Extension Directories: You can copy the external JAR files into Java Extension Directory [This is removed and not applicable from JDK 10].
- For Windows, the Java Extension Directory is located at "
set varname set varname=value set varname= set
61" [e.g., "set varname set varname=value set varname= set
62"]. - For macOS, the JDK extension directories are "
set varname set varname=value set varname= set
63" and "set varname set varname=value set varname= set
64". - For Ubuntu, the JDK extension directories are "
set varname set varname=value set varname= set
65" [e.g., "set varname set varname=value set varname= set
66"] and "set varname set varname=value set varname= set
67".
set varname set varname=value set varname= set
68". You can print its contents viaset varname set varname=value set varname= set
69. - For Windows, the Java Extension Directory is located at "
- User classes search path [in short, class path]: determined in the following order:
- Defaulted to the current working directory [
PATH PATH=path1;path1;path3;...
3]. - Entries in the
abc bash: abc: command not found
1 environment variable, which overrides the default. - Entries in the
set varname set varname=value set varname= set
72 [orset varname set varname=value set varname= set
73] command-line option, which overrides theabc bash: abc: command not found
1 environment variable. - The runtime command-line option
set varname set varname=value set varname= set
75, which override all the above.
set varname set varname=value set varname= set
76".
It is recommended that you use theset varname set varname=value set varname= set
72 [orset varname set varname=value set varname= set
73] command-line option [customized for each of your applications], instead of setting a permanentabc bash: abc: command not found
1 environment for all the Java applications. IDE [such as Eclipse/NetBeans] managesset varname set varname=value set varname= set
72 [set varname set varname=value set varname= set
73] for each of the applications and does not rely on theabc bash: abc: command not found
1 environment. - Defaulted to the current working directory [
If the Java Runtime ["
set varname set varname=value set varname= set54"] cannot find the classes used in your program in all the above places, it will issue error "Could not find or load main class xxxx" [JDK 1.7] or "java.lang.NoClassDefFoundError" [Prior to JDK 1.7].
Similarly, Java Compiler ["
set varname set varname=value set varname= set49"] will issue compilation errors such as "cannot find symbol", "package does not exist".
Notes: External native libraries ["
set varname set varname=value set varname= set85", "
set varname set varname=value set varname= set86", "
set varname set varname=value set varname= set87", "
set varname set varname=value set varname= set88"] are to be found in a path in JRE's Property "
set varname set varname=value set varname= set89", which normally but not necessarily includes all the directories in the
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable. Otherwise, you will get a runtime error "
set varname set varname=value set varname= set91".CLASSPATH Environment Variable
The
abc bash: abc: command not found1 environment variable could include directories [containing many class files] and JAR files [a single-file archive of class files]. If
abc bash: abc: command not found1 is not set, it is defaulted to the current directory. If you set the
abc bash: abc: command not found1, it is important to include the current working directory [
PATH PATH=path1;path1;path3;...3]. Otherwise, the current directory will not be searched.
A common problem in running hello-world program is:
abc bash: abc: command not found1 is set but does not include the current working directory. The current directory is therefore not searched, which results in "Error: Could not find or load main class Hello". You can simply remove the
abc bash: abc: command not found1, and leave the class path defaulted to the current directory.
For a beginner, no explicit
abc bash: abc: command not found1 setting is required. The default
abc bash: abc: command not found1 setting of current directory is sufficient. Remove all
abc bash: abc: command not found1 setting if there is any. However, if you have to set
abc bash: abc: command not found1, make sure that you include the current directory
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables02.
The
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables5 environment variable [for searching the executable programs] is applicable to all applications; while
abc bash: abc: command not found1 is used by Java only.
Read JDK documents "Setting the
abc bash: abc: command not found1" and "How Classes are Found" [you can find the hyperlinks from the index page of the JDK documentation, or googling].CLASSPATH Environment Variable [For Windows]
The
abc bash: abc: command not found1 accepts directories and jar-files. Path entries are separated by semicolon [
PATH PATH=path1;path1;path3;...5].
Example: Displaying and changing
abc bash: abc: command not found1 for the current CMD session.
You can set the
abc bash: abc: command not found1 permanently. See "How to Set an Environment Variable".CLASSPATH [for macOS/Ubuntu]
- To set the
abc bash: abc: command not found
1 for the current session, issue this command:set varname set varname=value set varname= set
9Use colon 'PATH PATH=path1;path1;path3;...
6' as the path separator [instead of semicolon 'PATH PATH=path1;path1;path3;...
5' in Windows]. - To set the
abc bash: abc: command not found
1 permanently, place the above export command in the bash shell initialization script [Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
14 orDisplay the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
15 of the home directory or// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile
1 for all users]. See "How to Set an Envrionment Variable".
JAVA_HOME and JRE_HOME
Many Java applications [such as Tomcat] require the environment variable
set VAR_NAME VAR_NAME=VAR_VALUE3 to be set to the JDK installed directory.How to Set JAVA_HOME in Windows
First, check if
set VAR_NAME VAR_NAME=VAR_VALUE3 is already set by start a CMD and issue:
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables0
If
set VAR_NAME VAR_NAME=VAR_VALUE3 is not set, you will receive "Environment variable JAVA_HOME not defined". Otherwise, the current setting will be shown.
To set/change
set VAR_NAME VAR_NAME=VAR_VALUE3 in Windows:
- Launch "Control Panel"
- "System"
- "Advanced system settings"
- Switch to "Advanced" tab
- "Environment variables"
- Choose "System Variables" [for all users]
- To add a new environment variable "
set VAR_NAME VAR_NAME=VAR_VALUE
3":- Choose "New"
- In "Variable Name", enter "JAVA_HOME".
- In "Variable Value", click "Browse Directory..." and navigate to the JDK installed directory [e.g., "
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
22"]. - OK ⇒ OK ⇒ OK.
- To change the existing "
set VAR_NAME VAR_NAME=VAR_VALUE
3" setting:- Select "
set VAR_NAME VAR_NAME=VAR_VALUE
3" ⇒ "Edit" - In "Variable Value", click "Browse Directory..." and navigate to the JDK installed directory [e.g., "
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables
22"]. - OK ⇒ OK ⇒ OK.
- Select "
You need to RE-START CMD for the new setting to take effect!
To verify the new setting, re-start CMD:
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables1How to Set JAVA_HOME in Linux/macOS [Bash Shell]
First, check if
set VAR_NAME VAR_NAME=VAR_VALUE3 is already set by start a terminal and issue:
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables2
set VAR_NAME VAR_NAME=VAR_VALUE3 is to be set to the JDK installed directory. You need to find your JDK installed directory.
[TODO] find macOS and Ubuntu JDK installed directory.
Add the the following line at the end of
// Refresh the bash shell source ~/.bashrc // or source ~/.bash_profile source ~/.profile source /etc/profile6" [or "
set varname set varname=value set varname= set08"]. Take note that filename beginning with dot [
PATH PATH=path1;path1;path3;...3] is hidden by default.
[TODO] How to un-hide for macOS/Ubuntu.
Display the value of the variable Set or change the value of the variable [Note: no space before and after '='] Delete the variable by setting to empty string [Note: nothing after '='] Display ALL the environment variables3
You need to refresh the bash shell for the new settings to take effect. Issue a "
abc bash: abc: command not found4" command as follows: