Use which to detect OS type

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