Both /etc/bashrc and ~/.bashrc are whats referred to as non-login files. Meaning they do not get sourced during a login shell unless called by /etc/profile or another file.

If /etc/profile calls it (as is typical) then if you want to test it in your current shell you have to either source it.

/root: #> source .bashrc (source with the command source)

/root: # . .bashrc (source with a period)

Or you have to instantiate a login shell by using su or sudo.

/root: # su - (the dash starts a login shell which will re-source login files)

/root: # sudo su - (using sudo to perform the switch user command)

and of course you could just re-login.

EDIT:

Typically though Java paths are not set using .bashrc they are set as separate scripts in the /etc/profile.d directory. At least on the enterprise distributions I use.

system1:/etc/profile.d # ll
-rw-r--r-- 1 root root  1438 Aug 30  2005 alljava.csh
-rw-r--r-- 1 root root  1682 Jul 13  2005 alljava.sh

system1:/etc/profile.d # cat alljava.sh
if [ -x /usr/$__libdir/jvm/java/bin/java ] || [ -x /usr/$__libdir/jvm/java/bin/jre ] ; then
export JAVA_BINDIR=/usr/$__libdir/jvm/java/bin
export JAVA_ROOT=/usr/$__libdir/jvm/java
export JAVA_HOME=/usr/$__libdir/jvm/java
#....cut for brevity...
Answer from 2bc on Stack Exchange
Discussions

java - JAVA_HOME in bashrc - Stack Overflow
Warning: JAVA_HOME environment variable is not set. Apache Maven 3.0.5 Maven home: /usr/share/maven Java version: 1.6.0_37, vendor: Sun Microsystems Inc. Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.19.0-25-generic", ... More on stackoverflow.com
🌐 stackoverflow.com
java - how to update JAVA_HOME in bashrc file - Stack Overflow
I am getting problem in bashrc file.After update in JAVA_HOME, I ran source bashrc but still it is pointing java-1.8.0 version.Please help me out. new changes in bashrc export JAVA_HOME=/home/sat... More on stackoverflow.com
🌐 stackoverflow.com
November 6, 2017
Set custom JAVA_HOME path
Well hello there Coming from ubuntu that it was just an entry in bashrc file , i am struggling to enter a custom path for the JAVA_HOME entry . I had tried to put the lines below in : .bashrc .zshrc make a shell script and run it export JAVA_HOME="/home/tsofras/work/dev/tools/Java/jdk-1.8" ... More on forum.manjaro.org
🌐 forum.manjaro.org
1
0
April 20, 2024
java - How to set JAVA_HOME in Linux for all users - Stack Overflow
I am new to Linux system and there seem to be too many Java folders. java -version gives me: java version "1.7.0_55" OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13) OpenJDK 64-Bit More on stackoverflow.com
🌐 stackoverflow.com
🌐
Curious Programmer
curiousprogrammer.dev › blog › set-java-home-in-linux
Set $JAVA_HOME in Linux | Curious Programmer
Add the path to $PATH export $PATH=$PATH:$JAVA_HOME · Save the file. Source the file in your terminal eg. source ~/.zshrc or source ~/.bashrc
🌐
LinuxForDevices
linuxfordevices.com › home › how to set the java_home variable in linux?
How to Set the JAVA_HOME Variable in Linux? - LinuxForDevices
September 16, 2020 - The steps to set JAVA_HOME variable for all users are similar to setting it for a single user. You will need to log in as root or execute the commands using the sudo command. Changes in global configurations are done by editing the /etc/bashrc file.
🌐
It's FOSS
itsfoss.com › set-java-home-ubuntu
How to Set JAVA_HOME Variable in Ubuntu Linux Correctly
November 17, 2023 - echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" >> ~/.bashrc · Verify that it has been correctly added to the end of the file: ... The above tail command will show the last 3 lines of the specified file. Here’s the entire output of the above three commands. Now, even if you exit the session or restart the system, the JAVA_HOME variable will still be set to the value you specified.
Find elsewhere
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › how to set java_home / path variables under linux bash profile
How to Set JAVA_HOME / PATH variables Under Linux Bash Profile - nixCraft
May 25, 2012 - Alternatively, type the following ... $ echo $JAVA_HOME $ echo $PATH Tip: Use the following command to find out exact path to which java executable under UNIX / Linux: $ which java · Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell. You need to setup global config in /etc/profile OR /etc/bash.bashrc file ...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_build_of_openjdk › 21 › html › configuring_red_hat_build_of_openjdk_21_on_rhel › configuring-javahome-environment-variable-on-rhel
Chapter 5. Configuring the JAVA_HOME environment variable on RHEL | Configuring Red Hat build of OpenJDK 21 on RHEL | Red Hat build of OpenJDK | 21 | Red Hat Documentation
The following example demonstrates using a text editor to enter commands for exporting JAVA_HOME in ~/.bashrc for a single user: > vi ~/.bash_profile export JAVA_HOME=/opt/jdk/11 export PATH="$JAVA_HOME/bin:$PATH" ... Be aware of the exact meaning of JAVA_HOME. For more information, see Changes/Decouple system java setting from java command setting.
🌐
Java67
java67.com › 2016 › 06 › how-to-set-javahome-and-path-in-linux.html
How to set JAVA_HOME and PATH in Linux? Example | Java67
Java developers like me always ... shell when you log in to Linux like bash_profile.sh, but you can also set JAVA_HOME into /etc/profile for all users....
🌐
Delft Stack
delftstack.com › home › howto › java › linux set java_home
How to Set Java_home in Linux | Delft Stack
February 26, 2025 - By adding the export command to the .bashrc file, you ensure that JAVA_HOME is set every time you log in. This method is excellent for users who work with Java frequently and need a consistent environment.
🌐
Red Hat
access.redhat.com › solutions › 1445833
How to set the JAVA_HOME environment variable? - Red Hat Customer Portal
It should point to the directory containing a bin/java executable. As the user who will use OpenJDK or any JDK vendor, open the shell configuration file. For the bash shell, this file is /home/username/.bashrc.
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › java › how to set java_home on windows, linux, & mac
How to Set JAVA_HOME on Windows, Linux, & Mac
March 5, 2025 - On Windows, you'll set JAVA_HOME in Advanced System Settings > Environment Variables. On a Mac, you'll need to add the Java path to your .zshrc file in a Terminal. On Linux, you can add the Java path to your .bashrc.
🌐
Stack Overflow
stackoverflow.com › questions › 47135622 › how-to-update-java-home-in-bashrc-file
java - how to update JAVA_HOME in bashrc file - Stack Overflow
November 6, 2017 - export PATH=${JAVA_HOME}/bin:${PATH} export JAVA_HOME=<path to java file> export JAVA_HOME=/home/janakan/Applications/jdk1.8.0_241 ... I guess it is the syntax that we need to use in bashrc file .
🌐
Medium
medium.com › @nirbhaysingh281 › set-java-home-environment-variable-permanently-f9d2c586609e
set JAVA_HOME environment variable Permanently - Nirbhay Singh - Medium
August 24, 2024 - To make this change persistent across sessions, you need to add the above commands to your shell configuration file (e.g., .bash_profile, .bashrc, or .zshrc), depending on the shell you're using. ... Now, the JAVA_HOME environment variable will be set every time you start a new shell session. After setting the JAVA_HOME, verify it by running: ... This should output /data/java11. ... Technophile, Assistant Vice President at CITI, talks about DevOps, Cloud, SRE, Linux and Programming.
🌐
thelinuxvault
thelinuxvault.net › blog › how-to-locate-and-set-java-home-directory-on-linux
How to Locate and Set JAVA_HOME Directory on Linux
For user-specific settings: Run source ~/.bashrc (or your shell’s profile file). For system-wide settings: Log out and back in, or reboot. Setting JAVA_HOME correctly is foundational for Java development and tooling on Linux. By following this guide, you can easily locate your Java installation and configure JAVA_HOME permanently or temporarily.
🌐
Dracula Servers
draculaservers.com › home › how to set java_home in linux
How to Set JAVA_HOME in Linux - Dracula Servers Tutorials
August 4, 2024 - This output confirms that JAVA_HOME is correctly set to the Java installation directory. If JAVA_HOME is not pointing to the correct directory, double-check the path you specified. Ensure that the directory exists and contains the Java installation. If changes to ~/.bashrc or ~/.zshrc are not ...
🌐
Baeldung
baeldung.com › home › java › set java_home variable in windows, mac os x, and linux
Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux | Baeldung
March 26, 2025 - To set JAVA_HOME in Linux for a single user, we can use /etc/profile or /etc/environment (preferred for system-wide setting) or ~/.bashrc (user-specific setting).