How to Add Symbolic Link of Specific Command using update-alternatives

Posted on

This article is showing the steps for installing specific command. The steps  are specifically compatible with any of device which runs with Debian or Ubuntu based operating system. The steps are also compatible with another different type of Linux-based operating system distribution. A proper adjustment of the command  in order to be able to perform the steps in another type of Linux-based operating system distribution is necessary. The adjustment is to change the package management tool command with the suitable command available in the running operating system.

It is still using the ‘update-alternatives’ command for installing a new symbolic link definition for a specific command.  The specific command for an example in this article is the ‘java’ command. The following are the steps to install symbolic link definition for ‘java’ command using ‘update-alternatives’ :

1. Make sure the command ‘update-alternatives’ is available in the operating system. Type ‘update-alternatives’ in the command line. If the command is not exist, read the article titled ‘How to install update-alternatives tool for maintaining symbolic link of a command’ in this link to install the package contains ‘update-alternatives’ tool.

2. If the command ‘update-alternatives’ exist in the operating system, type the command according to the following pattern :

update-alternatives --install symbolic_link_location command_name command_location priority

Description : 
update-alternatives : The command name for maintaining symbolic link
--install : Additional parameter for installing or defining a new symbolic link for a specific program name 
symbolic_link_location : The symbolic link file location
command_name : The name of the command represented by the symbolic link
command_location : The actual path of the command represented by the symbolic link
priority : The priority of the symbolic link 

Using the pattern above, this is the command for installing a new symbolic link to represent the java command :

root@hostname:~# update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 2
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
root@hostname:~#

To prove the command has already been successfully installed, type the following command in the command line :

update-alternatives --display java

Using the pattern above, the following is the command for checking the list of the available symbolic link representing ‘java’ program :

user@hostname:~$ update-alternatives --display java
java - auto mode
  link best version is /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  link currently points to /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  link java is /usr/bin/java
/opt/jdk1.8.0_181/bin/java - priority 1
/usr/lib/jvm/java-11-openjdk-amd64/bin/java - priority 2
user@alternatives:~$ 

Leave a Reply