skip to Main Content

I have a CentOS 7 VM. I recently installed 1.8.0_251 jdk version. Previous jdk version was 1.8.0_172. I inserted the following lines to a custom.sh script in /etc/profile.d/ to affect the new java version system-wide.

export PATH=/usr/java/jdk1.8.0_251-amd64/bin:$PATH
export JAVA_HOME="/usr/java/jdk1.8.0_251-amd64/"

I get the java version correctly.

[igwstuser@integrator1 ~]$ java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

Still I get the early version when JAVA_HOME is invoked through igwstuser. When JAVA_HOME is invoked through root user, I get the correct version. How can I resolve this?

[igwstuser@integrator1 ~]$ echo $JAVA_HOME
/usr/java/jdk1.8.0_172-amd64/
[igwstuser@integrator1 ~]$ sudo su
[root@integrator1 igwstuser]# echo $JAVA_HOME
/usr/java/jdk1.8.0_251-amd64/

3

Answers


    • Did you check your bashrc as “igwstuser”?
    • Is it pointing to the right java version?

    Just do this and check which java version it is pointing to with cat ~/.bashrc

    If you see some other java version then using text editor set correct value for export JAVA_HOME=

    After making necessary changes don’t forget to source bashrc to make changes available with source ~/.bashrc

    Login or Signup to reply.
  1. /etc/profile.d is for global users, for Linux env, this file runs first, then ~/.bash_rc and ~/.bash_profile for individual users.
    You need to check this user integrator1‘s ~/.bashrc and ~/.bash_profile, is there a JAVA_HOME set. If it is, change it to your latest JAVA_HOME. Then source it.

    Login or Signup to reply.
  2. Permissions on /etc/profile.d/custom.sh need to be open so all users can read the file during login. Only root can read it if only root is getting the setting.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search