我如何知道哪个环境变量文件正在覆盖我的“/etc/profile.d/jdk13.sh”?

我如何知道哪个环境变量文件正在覆盖我的“/etc/profile.d/jdk13.sh”?

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.

答案1

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.

相关内容