3

I want to be able to use the javac command on the CentOS 7 terminal. How do I set the PATH variable in order to accomplish this?

The following explains relevant aspects of my current environment. When I type cd /usr/lib/jvm and then ls -al, the output is:

total 8
drwxr-xr-x.  3 root root 4096 Dec 17 22:01 .
dr-xr-xr-x. 36 root root 4096 Dec 17 22:00 ..
drwxr-xr-x.  4 root root   95 Dec 17 22:01 java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
lrwxrwxrwx.  1 root root   21 Dec 17 22:01 jre -> /etc/alternatives/jre
lrwxrwxrwx.  1 root root   27 Dec 17 22:01 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx.  1 root root   35 Dec 17 22:01 jre-1.7.0-openjdk -> /etc/alternatives/jre_1.7.0_openjdk
lrwxrwxrwx.  1 root root   52 Dec 17 22:01 jre-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64 -> java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64/jre
lrwxrwxrwx.  1 root root   29 Dec 17 22:01 jre-openjdk -> /etc/alternatives/jre_openjdk

So how does this affect the syntax required to add javac to the path?

  • 1
    You have to install the openjdk-devel package in order to get javac (it's not part of the regular JRE package. not where I have a RHEL7 box right now but on RHEL 5 the package name is java-1.7.0-openjdk-devel – Bratchley Feb 13 '15 at 0:05
  • It's just a yum install of that package but it looks like didierc did it. – Bratchley Feb 13 '15 at 0:45
4

So how does this affect the syntax required to add javac to the path?

It doesn't affect your path settings. These links are configurable with the update-alternatives admin tool. See for instance this question on stackoverflow relevant to your case.

Normally, the java binaries should be available without modifying the PATH variable for java binary suites packaged for your distribution. If it weren't the case (either from a package, or because you installed a "3rd party" software suite), you may still instruct that tool about the location of the binaries, and then ask it to update the links accordingly.

calling javac from CentOS 7

As for the javac program, as indicated in the comments, you need a sdk package, your system seems to only have the jre installed.

This openjdk page gives succinct instructions about the installation process:

Fedora, Oracle Linux, Red Hat Enterprise Linux, etc.

On the command line, type:

 $ su -c "yum install java-1.7.0-openjdk"

The java-1.7.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.7.0-openjdk-devel package.

So the last part means running:

$ su -c "yum install java-1.7.0-openjdk-devel"

Once installed, if you have other java sdk installed, you may run

$ su -c "update-alternatives --config java"

to pick which sdk you would like to use by default.

  • Glad to be of help. – didierc Feb 13 '15 at 0:57

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.