1

I have a command which is:

./keytool

But I always have to go to this folder to use it:

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-2.b17.el7_1.x86_64/jre/bin

How can I just use the following command in my whole environment instead of defining the path every time?

keytool

How do I have to do this?

1
1

One way would be to create a symbolic link to any folder currently in your PATH-variable, in this example we use /usr/bin/.

sudo ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-2.b17.el7_1.x86_64/jre/bin/keytool /usr/bin/keytool
1

Add the following line at the end of the .bashrc (or .profile) file that is in your home directory :

export PATH=$PATH:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-2.b17.el7_1.x86_64/jre/bin

This is however a very fragile approach, since it will not work as expected as soon as you update your java installation. If you want to do it more properly, I suggest a couple of ways:

look in the /etc/alternatives folder, see if there's a link named javapointing to the current java home (could be pointing to another link). If it's there, change the export line with

export PATH=$PATH:/etc/alternatives/java

or (depending on your system), you could have a link in /usr/lib/jvm, something like /usr/lib/jvm/java pointing to the most recent version of the jvm you have installed. If it's there, you can use this one, so the export line is

export PATH=$PATH:/usr/lib/jvm/java

Apart from that, if you want it to be system-wide (instead of limiting the path extension to your user), you should add the line to /etc/bashrc (or /etc/bash-bashrc if it's there).

As a final note, this will only work in newly-created shells, not the ones you already have, unless you issue the command

. ~/.bashrc

(or the file you've modified, if it's not .bashrc) in those shells.

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.