AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 693353
Accepted
null
null
Asked: 2015-11-04 02:01:31 +0800 CST2015-11-04 02:01:31 +0800 CST 2015-11-04 02:01:31 +0800 CST

符号链接和 /etc/alternatives 的含义

  • 772

在我的控制台中输入时,会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. 我看不出有什么好处。

java
  • 2 2 个回答
  • 12801 Views

2 个回答

  • Voted
  1. A.B.
    2015-11-04T02:28:55+08:002015-11-04T02:28:55+08:00

    您已经在 Debian/Ubuntu 中发现了替代系统:

    试试看

    % 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.
    
    • 5
  2. Best Answer
    Sergiy Kolodyazhnyy
    2015-11-04T06:39:33+08:002015-11-04T06:39:33+08:00

    您寻求的答案在 AB 的答案中,更具体地说 - 在手册页的第二段和第三段的文本中。但简而言之,替代系统充当默认程序的数据库,允许优先考虑具有相同目的的多个不同程序

    好的,但为什么要绕路?为什么不 make /usr/bin/gnome-terminalbe launched or /usr/bin/xterm?维护系统软件。假设您同时安装了 Oracle 和 Open-JDK。您已将 Oracle java 设置为最高优先级,然后有一天决定将其删除。如果java,或者更确切地说/usr/bin/java是指向 Oracle 的 jdk 的任何二进制文件的链接,则您必须手动更改该链接。替代系统允许链接自动切换到优先列表中的下一个项目。

    • 4

相关问题

  • 如何使用类似 Qt 的 UI 在 KDE 中运行 Java 应用程序?

  • 如何安装 Minecraft?

  • 如何从命令行重新启动 java/flash?

  • Java和ALSA问题[关闭]

  • 无法安装 openSDK 6 - ubuntu 10.04

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve