0

I'm trying to install java-13 on Ubuntu 18.04 following this tutorial.

I've installed java-11 before which is preventing these commands taking effect

  sudo mv jdk-13 /opt/
  sudo tee /etc/profile.d/jdk13.sh <<EOF
  export JAVA_HOME=/opt/jdk-13
  export PATH=\$PATH:\$JAVA_HOME/bin
  EOF
  source /etc/profile.d/jdk13.sh

type java command gives this

java is hashed (/usr/bin/java)

I guess this is due to some setting in some environment variables config file e.g. $HOME/.profile.

How do I know which file is overwriting my /etc/profile.d/jdk13.sh?


I also tried this command

export PATH=\$JAVA_HOME/bin:\$PATH

and got

java -version
Command 'java' is available in '/usr/bin/java'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
3
1
+50

You've "installed java-11 before"… using the same/a similar procedure which includes creating a shell script in /etc/profile.d? And is it still installed? Have a look at the output of type java–this should tell you whether the binaries like java are (still?) found in another directory ("first"). If you want to use different versions in parallel, have a look at man update-alternatives (see https://askubuntu.com/a/233192/525098) which explains how to cleanly switch between versions of the same (suite of) program(s). This can include auxiliary scripts which modify PATH, or you could use a script which actually sets the environment variables based on the location of the java binary.

3
  • Thank you. type java command gives java is hashed (/usr/bin/java) what does that mean?
    – JJJohn
    Apr 2 '21 at 14:20
  • See unix.stackexchange.com/a/105878/238272 – however, while you explicitly can clear said command cache, the underlying problem should be the fact that your $PATH includes directory /usr/bin which contains a binary or link called java that always takes precedence. Try using export PATH=\$JAVA_HOME/bin:\$PATH above instead. Apr 3 '21 at 6:06
  • Thank you. I updated my post. I got Command 'java' is available in '/usr/bin/java' The command could not be located because '/usr/bin' is not included in the PATH environment variable.
    – JJJohn
    Apr 3 '21 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.