Linux Commands - Setting Alternatives

by
Jeremy Canfield |
Updated: November 22 2023
| Linux Commands articles
The alternatives command can be used to update a CLI in the /usr/bin directory to point to an alternative symbolic link.
For example, by default, /usr/bin/python is usually symbolically linked to /usr/bin/python2, like this.
~]$ ll /usr/bin/python
lrwxrwxrwx. 1 root root 36 Sep 25 23:30 /usr/bin/python -> /usr/bin/python2
The alternatives --set command can be used to have /usr/bin/python point to some other symbolic link, such as /usr/bin/python3.
alternatives --set python /usr/bin/python3
Or to have /usr/bin/java point to a specific version of Java.
alternatives --set java /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-3.el9.x86_64/jre/bin/java
After setting the alternative, there should be a listing in the /etc/alternatives directory with the symbolic link.
~]# ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 Nov 22 02:13 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-3.el9.x86_64/jre/bin/java
The alternatives --remove command can be used to remove the alternative.
alternatives --remove java /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-3.el9.x86_64/jre/bin/java
Did you find this article helpful?
If so, consider buying me a coffee over at