DEV Community

Cover image for Switching between binaries
Austin Cunningham
Austin Cunningham

Posted on • Edited on

Switching between binaries

I am constantly changing my binaries for installation prerequisites and testing. I used to spend a bit of time change paths or updating .bashrc . This is a quick example of a bit of bash I used to reduce the manual steps involve around changing the oc binary(Openshift command line binary). Currently I have four versions of the oc binary on my PC 3.7, 3.9, 3.10 and 3.11, I put each binary in its own directory in /opt/openshift

I have the oc binary sym-linked at /usr/local/bin/oc so I only need to change where the sym-link is pointing. This script checks the current version that is sym-linked , list the versions present on the PC , asks you what version you wish to install and removes the existing sym-link and adds an new one.

#!/bin/bash echo "########################################################################################" echo Current version of oc ls -la /usr/local/bin/oc echo "########################################################################################" echo Versions of openshift oc on the system ls /opt/openshift echo "########################################################################################" echo "What version do you wish to install ?" read version sudo rm /usr/local/bin/oc sudo ln -s /opt/openshift/$version/oc /usr/local/bin/oc echo " " echo "########################################################################################" oc version echo " " echo "########################################################################################" 
Enter fullscreen mode Exit fullscreen mode

Once you have your script written you can make it executable by changing the Linux permissions

chmod u+x change_oc.sh 
Enter fullscreen mode Exit fullscreen mode

It can then be run

./change_oc.sh 
Enter fullscreen mode Exit fullscreen mode

Running it looks like this

Myblog

Top comments (0)