When and Why run alternatives --install java jar javac javaws on installing jdk in linux

前端 未结 6 1756
耶瑟儿~
耶瑟儿~ 2021-02-14 08:56

To install java in linux (I used CentOS, RHEL is same too), I used this command

rpm -Uvh /path/to/binary/jdk-7u55-linux-x64.rpm

and verified java

相关标签:
6条回答
  • 2021-02-14 09:13

    These "alternatives" scripts and similar tools just symlink binaries of desired JDK version to the directories they are expected to be. It's done for all commands that should be available on your command line.

    Definition of "all" depends on your distro.

    0 讨论(0)
  • 2021-02-14 09:14

    To get a different version of java JRE/JDK as default in your OS:

    sudo alternatives --install /usr/bin/java java [path_to_java_bin] 1 
    

    Example in my case was:

    sudo alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_80/bin/java 1 
    

    Then run a config to select the alternative java version:

     sudo /usr/sbin/alternatives --config java
    

    Choose 1,2 or the option you desire

    Then check the changes by doing:

    java -version
    
    0 讨论(0)
  • 2021-02-14 09:19

    Maybe, just the guide is outdated.

    After you install the rpm, you can check:

    alternatives --display java

    to see if you can see the new version is controlled by alternative, if not you need to "--install" them; otherwise, I think you can just skip "--install" part.

    0 讨论(0)
  • 2021-02-14 09:24

    For Ubuntu use update-alternatives

    0 讨论(0)
  • 2021-02-14 09:30

    When you install JDK on Linux, what gets installed depends on the type of package, version and distribution. You can refer to the following links for information about the installation location on linux:

    JDK Installation for Linux Platforms - Version 8

    JDK Installation for Linux Platforms - Version 7

    Once you install JDK, the bin folder containing tools might not get added to the environment variable PATH. Commands typed on the terminal needs to be from the locations specified in the PATH variable. In cases when JDK\bin does not get added, the user would need to configure it manually as mentioned in Installing the JDK Software

    alternatives command is being used to create a symbolic link. Here, it is being directed to use the command to add the tools like javac, javaw to /usr/bin which exists in the PATH variable by default.

    If( you could execute java -version outside of JDK/bin && not by specifying the complete path && if the version and bundle prints to be as that of package you installed ){ you need not run the alternatives command.}

    0 讨论(0)
  • 2021-02-14 09:31

    java, javaws, javac, and jar are all different executables used by the JDK. When you run alternatives --config java you are only configuring which version of the java executable you wish to run. However, the JDK includes, for example, the javac compiler. You need to configure which version of the compiler you wish to use as well.

    The alternatives command is, in a nutshell, used to maintain a lookup for symbolic (or sym) links. Before you can choose which version of java you want to run with the --configure option, you must first register the actual path to the executable with the --install option. alternatives --install is not installing any software. It is merely registering some paths and aliases with the alternatives framework. (Note: alternatives is not using the alias command. I mean "aliases" in the traditional, literal sense.)

    You should also understand what the rpm command does. Really, it is only dropping down a set of binaries into a particular directory. This directory may be long and tedious to explicitly specify: /some/path/to/lib/jvm/java-1.x.x-etc-etc-x86/jre/bin/java. You don't want to specify this every time you want to run java. Instead, we set up some sym links.

    You might also want to read up on how the PATH works in linux.

    It may become clearer if you try tracing through the setup for your machine. Here is what I ran:

    > which java
    /usr/bin/java
    > ls -l /usr/bin/java
    lrwxrwxrwx 1 root root 22 Aug 14  2014 /usr/bin/java -> /etc/alternatives/java
    > ls -l /etc/alternatives/java
    lrwxrwxrwx 1 root root 73 Aug 14  2014 /etc/alternatives/java -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.fc19.x86_64/jre/bin/java
    
    0 讨论(0)
提交回复
热议问题