2

I would like to change the PATH of my Debian 7.1.0 system to link to the Java version I want. If I enter in the terminal:

java -version

I get:

java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1~deb7u1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

This is the Java version preinstalled by my distribution. I have now downloaded the Sun JDK 1.7.0 update 25. I would like my system to use this version instead of the preinstalled version. I have made two changes to my PATH in .bashrc but I still have the same Java version.

My .bashrc file contains the lines:

PATH="PATH":/usr/local/jdk1.7.0_25
export PATH
2
  • Ok. Now it works. I have to add /bin and restart the current session
    – Mazzy
    Commented Sep 5, 2013 at 16:56
  • It works but I lost the original PATH and the possibility to use all the command
    – Mazzy
    Commented Sep 5, 2013 at 17:05

3 Answers 3

4

What you actually want is this in your ~/.profile (or .bashrc if you insist, but .profile is better):

PATH=$PATH:/usr/local/jdk1.7.0_25/bin
export PATH

You were losing the original $PATH because you were using "PATH" instead of $PATH so it was interpreted as a simple string and all you were doing is setting your path to:

PATH:/usr/local/jdk1.7.0_25/bin
4

You probably want the oracle java bin prepended (not appended) to your path:

export PATH=/usr/local/jdk1.7.0_25/bin:$PATH

Since the execution path is a list of directories that are checked in order (so if you append the jdk7 bin to $PATH, the distro java found be found first instead).

I lost the original PATH and the possibility to use all the command

Notice the difference between these two:

PATH=$PATH
PATH=PATH

When you assign to a shell variable, use just the word, PATH. When you reference a shell variable, you must prefix it with $. For example:

FOO="hello"
FOO=$FOO" world"

$FOO now equals "hello world". But:

FOO="hello"
FOO=FOO" world"

$FOO now equals "FOO world".

Don't overwrite $PATH -- append or prepend to it.

0

In addition to ~/.profile and ~/.bashrc, the Java path can also be set via

/etc/profile.d/jdk.sh

If you take a look at /etc/profile, you'll see that it sources all the scripts inside /etc/profile.d/.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .