Use which to detect OS type

Command brew should not be used while detecting OS type. This emits error like 'command not found' in systems where brew is not installed.