Error: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun code example

Example 1: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

xcode-select --install

Example 2: xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer),

$ sudo xcode-select -r
$ sudo xcode-select --switch /Library/Developer/CommandLineTools