'Why does this script works on one machine but not on the other? MacOS Catalina

I have this shell script which works on my machine just fine. To test the script I have a VM with the same OS Version, MacOSCatalina. On the "real machine" the script works just fine but on the VM there is always the error:

syntax error in a conditional expression, syntax error near ]]

Here is the script:

echo "check if Homebrew needs to be installed" 
echo "Homebrew is a package manager for macOS"
sleep 2
which -s brew
if [[ $? != 0 ]]
then
    echo "Homebrew is not installed, installing Homebrew now"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    echo "Homebrew is already installed"
fi
sleep 2
echo ""
echo "check if node.js needs to be installed"
echo "node.js is a needed library for angular"
sleep 2
which -s node
if [[ $? != 0 ]]
then
    echo "node.js is not installed, installing node.js now"
    brew install node
else
    echo "node.js is already installed"
fi
sleep 2
echo ""
echo "check if Angular needs to be installed"
echo "Angular as a huge framework serves as the frontend in our project"
sleep 2
which -s ng
if [[ $? != 0 ]]
then
    echo "Angular is not installed, installing Angular now"
    npm install angular
else
    echo "Angular is already installed"
fi
echo ""
echo "Done"


Solution 1:[1]

I don't seen any syntax errors, but you can do away with [[ entirely.

For example,

if ! which -s brew
then
    echo "Homebrew is not installed, installing Homebrew now"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    echo "Homebrew is already installed"
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chepner