심볼릭 링크와 / etc / alternatives의 의미


8

java콘솔에 입력 할 때 심볼릭 링크 /usr/bin/java가 이어집니다.

which java
/usr/bin/java

이 심볼릭 링크는을 가리 킵니다 /etc/alternatives/java.

file /usr/bin/java
/usr/bin/java: symbolic link to `/etc/alternatives/java' 

/ etc / alternatives / java는 다음을 가리키는 기호 링크 자체입니다. /usr/lib/jvm/jdk1.8.0_20/bin/java

왜 그런 우회가 이루어 집니까? 왜하지 않습니다 java직접 가리 킵니다 /usr/lib/jvm/jdk1.8.0_20. 나는 어떤 이점도 보지 못한다.

답변:


4

당신이 찾는 대답은 AB의 대답, 더 구체적으로-맨 페이지의 텍스트, 두 번째 및 세 번째 단락에 있습니다. 그러나 이것을 간단히 말하면 대안 시스템은 기본 프로그램의 데이터베이스 역할을하므로 동일한 목적으로 여러 가지 다른 프로그램의 우선 순위를 지정할 수 있습니다

그래, 왜 우회인가? 왜 /usr/bin/gnome-terminal시작 하지 /usr/bin/xterm않습니까? 시스템 소프트웨어를 유지합니다. Oracle과 Open-JDK가 모두 설치되어 있다고 가정하십시오. Oracle java를 최우선 순위로 설정 한 후 언젠가는 제거하기로 결정했습니다. 경우 java, 또는 오히려이 /usr/bin/java오라클의 JDK 무엇이든 바이너리에 대한 링크했다, 당신은 수동으로 링크를 변경해야 할 것입니다. 대체 시스템은 링크가 우선 순위 목록의 다음 항목으로 자동 전환되도록합니다.


5

데비안 / 우분투에서 대안 시스템을 발견했습니다.

사용해보십시오

% sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java         1082      auto mode
  1            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/java-8-openjdk-i386/jre/bin/java   1081      manual mode
* 3            /usr/lib/jvm/java-8-oracle/jre/bin/java         1082      manual mode

Press <enter> to keep the current choice[*], or type selection number:

에서 man update-alternatives

update-alternatives - maintain symbolic links determining default commands

DESCRIPTION
    update-alternatives creates, removes, maintains and displays 
    information about the symbolic links comprising the Debian
    alternatives system.

    It  is  possible  for several programs fulfilling the same or similar
    functions to be installed on a single system at the same time.  For
    example, many systems have several text editors installed at once.
    This gives choice to the users of a system, allowing each to use a
    different editor, if desired, but makes it difficult for a program to
    make a good choice for an editor to invoke if the user has not
    specified a particular preference.

    Debian's alternatives system aims to solve this problem.  A generic
    name in the filesystem is shared by all files providing
    interchangeable functionality.  The alternatives system and the
    system administrator together determine which actual file is
    referenced  by  this generic name.  For example, if the text editors
    ed(1) and nvi(1) are both installed on the system, the alternatives
    system will cause the generic name /usr/bin/editor to refer to
    /usr/bin/nvi by default. The system administrator can override this
    and cause it to refer to /usr/bin/ed instead, and the alternatives
    system will not alter this setting until explicitly requested to do
    so.

    The generic name is not a direct symbolic link to the selected
    alternative.  Instead, it is a symbolic link to a name in the
    alternatives directory, which in turn is a symbolic link to the
    actual file referenced.  This is done  so  that  the  system
    administrator's changes can be confined within the /etc directory:
    the FHS (q.v.) gives reasons why this is a Good Thing.

    When  each  package  providing  a  file with a particular
    functionality is installed, changed or removed, update-alternatives
    is called to update information about that file in the alternatives
    system.  update-alternatives is usually called from the
    postinst (configure) or prerm (remove and deconfigure) scripts in
    Debian packages.

    It is often useful for a number of alternatives to be synchronized,
    so that they are changed as a group; for example, when several 
    versions of the vi(1) editor are installed, the man page referenced
    by /usr/share/man/man1/vi.1 should  correspond  to the executable
    referenced by /usr/bin/vi.  update-alternatives handles this by means
    of master and slave links; when the master is changed, any associated
    slaves are changed too.  A master link and its associated slaves make
    up a link group.

    Each  link  group is, at any given time, in one of two modes:
    automatic or manual.  When a group is in automatic mode, the
    alternatives system will automatically decide, as packages are
    installed and removed, whether and how to update the links.  In
    manual mode, the alternatives system will retain the choice of the
    administrator and avoid changing the links (except when something is
    broken).

    Link groups are in automatic mode when they are first introduced to
    the system.  If the system administrator makes changes to the
    system's automatic settings, this will be noticed the next time
    update-alternatives is run on the changed link's group, and the group
    will automatically be switched to manual mode.

    Each alternative has a priority associated with it.  When a link
    group is in automatic mode, the alternatives pointed to by members of
    the group will be those which have the highest priority.

    When  using  the  --config option, update-alternatives will list all
    of the choices for the link group of which given name is the master
    alternative name.  The current choice is marked with a ‘*’.  You will
    then be prompted for your choice regarding this link group.
    Depending on the choice made, the link group might no longer be in
    auto mode. You will need to use the --auto option in order to return
    to the automatic mode (or you can rerun --config and select the entry
    marked as automatic).

    If you want to configure non-interactively you can use the --set
    option instead (see below).

    Different packages providing the same file need to do so
    cooperatively.  In other words, the usage of update-alternatives is
    mandatory for all involved packages in such case. It is not possible
    to override some file in a package that does not employ the
    update-alternatives mechanism.

Linux Mint 18 Cinnamon에서 /etc/profile.d/jdk_home.sh를 확인하십시오.이 파일의 이름을 jdk_home.sh.old로 바꾸면 경로가 계속 재정의되지 않고 java -version을 호출하고 Java 9를 볼 수 있습니다. 예상했다. update-aternatives --config java에서 Java 9를 올바르게 선택했지만이 jdk_home.sh 파일은 $ PATH를 계속 무시했습니다.
flyingdrifter
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.