I understand the motivation behind your question. update-alternatives elegantly solves the problem of managing several installed versions of a program (for example Java) or different ports of a program (vim vs. elvis vs. vile) by making one of them the default one.

update-alternatives, found in many Linux distros, creates and manages a set of symlinks from /bin, /usr/bin (and the like) to /etc/alternatives, and from there to the location where the program is installed.

For example, in openSUSE java is symlinked to /etc/alternatives/java, which is symlinked to a "private" path where java resides:

/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib64/jvm/java-1.5.0-sun-1.5.0/jre/bin/java

Unfortunately, and although some think it would be necessary, at least for MacPorts, there is no such thing in OS X. I have personally solved the lack of update-alternatives with aliases in my .bashrc:

alias ls='/usr/local/bin/ls'

or simply changing $PATH:

PATH=/usr/local/bin:$PATH

If you can't solve it like this and are weighing the fact of porting it to OS X be aware that although update-alternatives' first incarnation was a Perl script, it was rewritten in C for Debian, and some other distros adopted it later (for instance openSUSE 12.1).

openSUSE 11.4 provides the Perl version as an RPM package. If you are looking for the C version, go for any recent Ubuntu or Debian release, or openSUSE 12.1 or later.

Answer from jaume on Stack Exchange
Top answer
1 of 2
13

I understand the motivation behind your question. update-alternatives elegantly solves the problem of managing several installed versions of a program (for example Java) or different ports of a program (vim vs. elvis vs. vile) by making one of them the default one.

update-alternatives, found in many Linux distros, creates and manages a set of symlinks from /bin, /usr/bin (and the like) to /etc/alternatives, and from there to the location where the program is installed.

For example, in openSUSE java is symlinked to /etc/alternatives/java, which is symlinked to a "private" path where java resides:

/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib64/jvm/java-1.5.0-sun-1.5.0/jre/bin/java

Unfortunately, and although some think it would be necessary, at least for MacPorts, there is no such thing in OS X. I have personally solved the lack of update-alternatives with aliases in my .bashrc:

alias ls='/usr/local/bin/ls'

or simply changing $PATH:

PATH=/usr/local/bin:$PATH

If you can't solve it like this and are weighing the fact of porting it to OS X be aware that although update-alternatives' first incarnation was a Perl script, it was rewritten in C for Debian, and some other distros adopted it later (for instance openSUSE 12.1).

openSUSE 11.4 provides the Perl version as an RPM package. If you are looking for the C version, go for any recent Ubuntu or Debian release, or openSUSE 12.1 or later.

2 of 2
1
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.

Macports supports this capability via 'port select' for many language packages, mysql, and others. (I'm using version MacPorts 2.4.2.)

🌐
Command Not Found
command-not-found.com › update-alternatives
command-not-found.com – update-alternatives
Add a symbolic link: sudo update-alternatives --install path/to/symlink command_name path/to/command_binary priority
Discussions

java - sudo: update-alternatives: command not found - Stack Overflow
I am trying to install Java version 8 on my MacOS. The installation guideline advises typing this command: sudo update-alternatives --install /usr/bin/java java /usr/lib/java/JDk.../bin/java ... IIRC, update-alternatives is not a MacOS command, but a Linux command. More on stackoverflow.com
🌐 stackoverflow.com
March 26, 2020
linux command --> macos command equivalent
I don't know; I'm here because I use Linux. More on reddit.com
🌐 r/linuxquestions
5
0
August 26, 2021
macos - How to update Java to 7 on max OSX? - Stack Overflow
This command worked for me on a Linux-based machine, so I think there would be no different than a Mac, but I'm not sure, you could try it out. ... @user3025403, then the only way to change the Java version is by setting/changing the Java environment variables. If you google it up, you will find enough questions and answers about it. Good luck! 2014-06-06T20:26:00.06Z+00:00 ... update-alternatives ... More on stackoverflow.com
🌐 stackoverflow.com
update-alternatives broken and php no longer found in cmd - Stack Overflow
I tried to switch the php version from 7.4 to 8.0 on my ubuntu operating system and wanted to use update-alternatives. I entered the following command, which broke everything: sudo update-alternati... More on stackoverflow.com
🌐 stackoverflow.com
🌐
The Geek Diary
thegeekdiary.com › update-alternatives-command-not-found
update-alternatives: command not found – The Geek Diary
If you encounter below error: update-alternatives: command not found · you may try installing below package as per your choice of distribution. 1. Add a symbolic link: $ sudo update-alternatives --install path/to/symlink command_name path/to/command_binary priority ·
🌐
Stack Overflow
stackoverflow.com › questions › 60863458 › sudo-update-alternatives-command-not-found
java - sudo: update-alternatives: command not found - Stack Overflow
March 26, 2020 - The installation guideline advises typing this command: sudo update-alternatives --install /usr/bin/java java /usr/lib/java/JDk.../bin/java ... IIRC, update-alternatives is not a MacOS command, but a Linux command.
🌐
Blogger
gochev.blogspot.com › 2019 › 07 › use-multiple-jvm-versions-on-mac-os-and.html
Use Multiple JVM versions on Mac OS and Linux
Edit your ~/.bashrc file alias java11='sudo update-alternatives --set java /opt/sapmachine-jdk-11.0.3/bin/java;export JAVA_HOME=/opt/sapmachine-jdk-11.0.3/' alias java8='sudo update-alternatives --set java /opt/java-8-oracle/bin/java;export JAVA_HOME=/usr/lib/java-8-oracle/' SAVE and start a new bash terminal execute java8 to use java8 java11 to use java11 the latest version you have set stays as system wide, but the JAVA_HOME is not :( you can put java8 or java11 as a last line in the bashrc but since it is sudo it will always require password when start and is not great ;(
🌐
Loginroot
pkgs.loginroot.com › errors › notFound › update-alternatives
update-alternatives: command not found
[root@server ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin If it's empty, You may set the PATH variable with this command · export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" /usr/sbin/update-alternatives - from package: chkconfig You may install the required package with command yum install {package}
🌐
Reddit
reddit.com › r/linuxquestions › linux command --> macos command equivalent
r/linuxquestions on Reddit: linux command --> macos command equivalent
August 26, 2021 -

linux command --> macos command equivalent

I came across an linux sudo command that I need to port to macos.

sudo update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force

This command should set the priority when calling ninja to /usr/local/bin/ninja (* Am I right? *)

What's the equivalent command for MacOS?

EDIT:

This is the 3 lines of codes that I need to port to MacOS.

The third is for a specific environment for a python program to run.

!wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip

!sudo unzip ninja-linux.zip -d /usr/local/bin/

!sudo update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force

Find elsewhere
Top answer
1 of 2
1

Oracle Java 7 and Apple Java 6 are completely different and they coexist on the same machine as they inhabit totally separate locations.

Java 7, if installed, lives in:

/Library/"Internet Plug-Ins"/JavaAppletPlugin.plugin/Contents/Home

Java 6, if installed, lives in:

/System/Library/Frameworks/JavaVM.framework/Versions/A/

(And the more traditional Java 6 JDK is at: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home)

When you type java, you're running /usr/bin/java, which is a symbolic link to Java 6. In fact, if you type ls -l /usr/bin | grep -i java you will see a bunch of symbolic links for the typical JDK/JRE executables.

So if you have installed Java 7, and that's what you want to use from the command line, you can change into its directory and run its specific binaries in bin. To avoid that, you can add its bin directory to your Bash search path, so its contents are invoked instead of the Java 6 symlinks in /usr/bin. To do this, alter /etc/paths to add the bin directory before the first line:

{ echo "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"; \
  cat /etc/paths; } | sudo tee /etc/paths > /dev/null

Then set the JAVA_HOME environment variable, so supporting software knows where to find Java 7:

{ echo -n "export JAVA_HOME=";
echo "/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"; } \
| sudo tee -a /etc/bashrc > /dev/null

Now, in any new Terminal window, when you type java -version, you'll see java version "1.7.0_51". (And if you still want to be able to run the Java 6 binaries, you can call them with /usr/bin/java, /usr/bin/javac, etc.)

2 of 2
1

You could try issuing the following command:

update-alternatives –config java

That command will make you able to choose between Java versions. This command worked for me on a Linux-based machine, so I think there would be no different than a Mac, but I'm not sure, you could try it out.

🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - sudo update-alternatives --install ... you encounter an error stating that there are no alternatives for a command, it’s likely that the alternative has not been installed yet....
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
SOLVED - linux command "update-alternatives" not available on 19.3 - Linux Mint Forums
December 28, 2019 - update-alternatives update-alternatives: need --display, --query, --list, --get-selections, --config, --set, --set-selections, --install, --remove, --all, --remove-all or --auto Try ... If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help. Regards, Deepak Mint 22.2 Cinnamon on 2 disks/8gb ... Obviously that was tried... (but I agree , should have reported it) ... $ sudo apt-get install update-alternatives Reading package lists...
🌐
Baeldung
baeldung.com › home › administration › the update-alternatives command in linux
The update-alternatives Command in Linux | Baeldung on Linux
July 24, 2024 - $ sudo update-alternatives --set editor /usr/bin/vim.tiny update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/editor (editor) in manual mode ... So, the change of the editor‘s alternative is reflected by the appropriate change to the manual. Let’s notice that we can set slaves links not only to documentation but also to configuration or even other executable files. So we have a flexible way to change the whole surroundings of the program with one command.
🌐
Medium
medium.com › @petehouston › switch-java-versions-on-any-systems-you-like-f0c996b4f57a
Switch Java versions on any systems you like | by Pete Houston | Medium
October 8, 2016 - So to switch version, use the following command, /usr/libexec/java_home -v MAJOR.MINOR.MACRO_UPDATE · Use the alternative configuration tool, sudo update-alternatives — config java · Use the alternative configuration tool, but first, you ...
🌐
SUSE
documentation.suse.com › sles › 15-SP7 › html › SLES-all › cha-update-alternative.html
update-alternatives: managing multiple versions of commands and files | Administration Guide | SLES 15 SP7
May 12, 2024 - To remove an alternative, use the following command: > sudo update-alternatives --remove foo /usr/local/bin/foo-2 · After this script has been removed, the alternatives system for the foo group looks like this: > sudo update-alternatives --display foo foo - auto mode link best version is /usr/local/bin/foo-3 link currently points to /usr/local/bin/foo-3 link foo is /usr/local/bin/foo /usr/local/bin/foo-3 - priority 300 · If you have alternatives, the script itself is not enough.
🌐
openSUSE Forums
forums.opensuse.org › english › applications
update-alternative - Applications - openSUSE Forums
February 10, 2012 - Good Day Guys, just want to as about the following code sudo update-alternatives -h result sudo: update-alternatives: command not found can you help me about this, I want to use this command want to try Oracle JDK and this command is needed based on the instruction https://sites.google.com...
🌐
LinuxQuestions.org
linuxquestions.org › questions › mandriva-30 › alternatives-command-not-working-384654
alternatives command not working
November 19, 2005 - I am installing Java and following these instructions. When I use the alternatives command I get this response. [timb@Home timb] su - [root@Home root]
Top answer
1 of 12
84

Assuming one has installed a JDK in /opt/java/jdk1.8.0_144 then:

  1. Install the alternative for javac

    $ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_144/bin/javac 1
    
  2. Check / update the alternatives config:

    $ sudo update-alternatives --config javac
    

If there is only a single alternative for javac you will get a message saying so, otherwise select the option for the new JDK.

To check everything is setup correctly then:

$ which javac
/usr/bin/javac

$ ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 Sep  4 17:10 /usr/bin/javac -> /etc/alternatives/javac

$ ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 32 Sep  4 17:10 /etc/alternatives/javac -> /opt/java/jdk1.8.0_144/bin/javac

And finally

$ javac -version
javac 1.8.0_144

Repeat for java, keytool, jar, etc as needed.

2 of 12
76

You will notice a big change when selecting options if you type in "java -version" after doing so. So if you run update-alternatives --config java and select option 3, you will be using the Sun implementation.
Also, with regards to auto vs manual mode, making a selection should take it out of auto mode per this page stating:

When using the --config option, alternatives will list all of the choices for the link group of which given name is the master link. You will then be prompted for which of the choices to use for the link group. Once you make a change, the link group will no longer be in auto mode. You will need to use the --auto option in order to return to the automatic state.

And I believe auto mode is set when you install the first/only JRE/JDK.

🌐
Puppy Linux Discussion Forum
oldforum.puppylinux.com › board index › house training › users ( for the regulars )
update-alternatives command not found - (old)Puppy Linux Discussion Forum
Thanks I am running Lucid Puppy version 5.2.5 result I want to see is: pressing Shift + H print the Arabic lettre: ﻻ pressing Shift +T print the Arabic lettre: ﻹ Lettres in Arabic change shape depending on their position in the word Now, for example,the word الثـﻻثاء Should be writen الثـلاثاء on the first shape is not perfectly tied to the next letter (Arabic is RTL) On Ubuntu, thiis achieve simply by ... update-alternatives --set xinput-all_ALL /etc/X11/xinit/xinput.d/default-xim which in Ubuntu returns ... Using '/etc/X11/xinit/xinput.d/default-xim' to provide 'xinput-all_ALL' Using google, I found this fix for fedora