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

Posted on

This article exists to show how to remove symbolic link of specific command using the ‘update-alternatives’ tool. The tool ‘update-alternatives’ is part of dpkg package. There is no¬† need to install a new package to execute the tool. Just type the command in the command line to make sure it works. The following is the output of the execution of the command line :

update-alternatives

In order to remove certain symbolic link using the ‘update-alternatives’ command, there are several steps taken for completing the task. Those steps are :

1. Execute the command to check that it exists in the operating system.

user@hostname:~$ update-alternatives 
update-alternatives: need --display, --query, --list, --get-selections, --config, --set, --set-selections, --install, --remove, --all, --remove-all or --auto

Use 'update-alternatives --help' for program usage information.
user@hostname:~$

3. Before removing the specific symbolic link representing the ‘java’ command, check the symbolic link first. Below is the command for checking the symbolic link :

update-alternatives --display command_name

Description : 
update-alternatives : The command for maintaining symbolic link
--display : Additional parameter for listing or displaying the available symbolic link
command_name : The command name which is selected for further symbolic link listing

Using the pattern above, the command for listing the symbolic link available for the ‘java’ program :

root@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
root@hostname:~#

3. Using the symbolic link list as shown in the output before in the previous step, choose the symbolic link for further removal process. Below is the pattern of the command for removing the specific symbolic link :

update-alternatives --remove "command_name" "program_location"

Description : 
update-alternatives : The command for maintaining symbolic link for a specific command or program
--remove : Additional parameter for removing specific symbolic link
"command_name" : The command where the symbolic link represents
"program_location" : The location of the program or command

Using the pattern command above, remove the selected symbolic link by typing the following command :

root@hostname:~# update-alternatives --remove "java" "/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
update-alternatives: using /opt/jdk1.8.0_181/bin/java to provide /usr/bin/java (java) in auto mode
root@soulreaper:~#

4. Don’t forget to check the symbolic link list again to make sure that the chosen symbolic link has been completely removed. Just retype the command for displaying the symbolic link list :

root@hostname:~# update-alternatives --display java
java - auto mode
  link best version is /opt/jdk1.8.0_181/bin/java
  link currently points to /opt/jdk1.8.0_181/bin/java
  link java is /usr/bin/java
/opt/jdk1.8.0_181/bin/java - priority 1
root@hostname:~# 

Leave a Reply