• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

update-alternatives: command not found

by admin

When you install Java, it usually means one of two things: you are installing the Java Runtime Environment (JRE) or the Java Development Kit (JDK). The JRE provides the runtime that allows you to run Java programs, whereas the JDK contains the JRE, as well as other tools, that allow you to develop in Java.

We are going to install the JDK here, but to complicate things further, there are different implementations of the JDK—OpenJDK, Oracle Java, IBM Java—and the one we will be using is the default-jdk APT package, which comes with our Ubuntu installation:

$ sudo apt update
$ sudo apt install default-jdk

Next, we need to set a system-wide environment variable so that other programs using Java (for example, Elasticsearch) know where to find it. Run the following command to get a list of Java installations:

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
  1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
  2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

Press [enter] to keep the current choice[*], or type selection number: 

If you have multiple versions of Java on your machine, you’ll be prompted to select the one you prefer. If you encounter below error:

update-alternatives: command not found

you may try installing below package as per your choice of distribution.

Distribution Command
OS X brew install dpkg
Debian apt-get install dpkg
Ubuntu apt-get install dpkg
Alpine apk add dpkg
Kali Linux apt-get install dpkg
CentOS yum install chkconfig
Fedora dnf install chkconfig
Raspbian apt-get install dpkg
Docker docker run cmd.cat/update-alternatives update-alternatives

update-alternatives Command Examples

1. Add a symbolic link:

$ sudo update-alternatives --install path/to/symlink command_name path/to/command_binary priority

2. Configure a symbolic link for “java”:

$ sudo update-alternatives --config java

3. Remove a symbolic link:

$ sudo update-alternatives --remove java /opt/java/jdk1.8.0_102/bin/java

4. Display information about a specified command:

$ update-alternatives --display java

5. Display all commands and their current selection:

$ update-alternatives --get-selections

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to adjust the telnet timeout (and how to disable it)
  2. date Command Examples in Linux
  3. net-snmp-create-v3-user: command not found
  4. What is the purpose of “mysql.sys@localhost” user
  5. ‘nestat -s’ showing a large number for “packet reassembles failed” errors in CentOS/RHEL
  6. kill Command Examples in Linux
  7. qm migrate Command Examples in Linux
  8. Beginners guide to Apache HTTP Server – Installation and Configuration
  9. pkgfile Command Examples in Linux:
  10. Basic “chmod” Command examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • raw: command not found
  • raw Command Examples in Linux
  • rankmirrors Command Examples in Linux
  • radeontop: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright