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:

export PATH
  • Ok. Now it works. I have to add /bin and restart the current session – Mazzy Sep 5 '13 at 16:56
  • It works but I lost the original PATH and the possibility to use all the command – Mazzy Sep 5 '13 at 17:05

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

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:


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:


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=$FOO" world"

$FOO now equals "hello world". But:

FOO=FOO" world"

$FOO now equals "FOO world".

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


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


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

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.