簡體   English   中英

什么是 linux 中的 update-alternatives 命令,它的用途是什么?

[英]what is update-alternatives command in linux and what is the use of it?

在 Linux 中安裝 java 時,有一些 update-alternatives 命令的用法,因為我是 Linux 環境的新手,我想知道這個命令的作用以及它的用途

>>sudo update-alternatives --install /usr/bin/java java /usr/lib/java/JDk.../bin/java

基本上它告訴你的機器使用Jave JDK的替代品而不是默認的那個,在Linux系統中,它是OpenJDK。

手冊頁的簡要摘錄比我寫的任何答案都要好:

update-alternatives創建,刪除,維護和顯示有關包含Debian替代系統的符號鏈接的信息。

   It is possible for several programs fulfilling the same or similar functions to be installed on a single  sys‐
   tem  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 prefer‐
   ence.

   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.

使用--install,您指定了一個鏈接,“/ usr / bin / java”名稱為“java”,路徑為“/ usr / lib / java / JDK ....”,並為系統添加了一組備選方案。 link是主鏈接的通用名稱,name是alternative目錄中其符號鏈接的名稱,path是為主鏈接引入的替代方法。

我希望足夠清楚,這里有一篇關於java替代品帖子

對於完整的使用列表,我建議查看相同的手冊頁,在OS shell上鍵入man update-alternatives;

我想從頭開始為您解釋...如果您有 2 個或更多版本的程序以 linux 中的相同命令開頭,您可以使用 update-alternatives 命令來確定該程序的默認版本,您也可以更改該命令的默認版本很容易..假設您的系統上有 2 個版本的 python。 python 2 & python 3. 默認情況下,linux 上的 python 命令在 shell 上啟動 python2 解釋器。 你認為 python 2 是舊的,你想使用 python 3 而不是 python2 。 解決方案之一是您在 shell 上輸入 python3 命令並啟動其版本超過 3 的 python 解釋器......但是您想輸入 python 命令並且 shell 識別您要運行 python3 解釋器。 在這里,update-alternatives 命令完成它的工作,並確定您要用於特定命令的程序的默認版本和版本。

我告訴過你 python 命令默認啟動 python 2 解釋器。 你想改變它。 根據例子 :

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1.

當您在 linux 上執行此命令時,您會告訴 shell,在此之后,兩個不同程序的兩個鏈接鏈接到 linux 上的 python 命令。事實上,您在 linux 上的 python 命令上安裝了 python3 程序,並且兩個程序存在於 1 個命令中您可以通過更改命令中的優先級或手動配置來設置默認程序來更改這些程序的默認值並運行您想要的這些程序。

希望這對你有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM