I encountered the same question on Windows.
A command!{sys.executable} -m pip install 'git+https://github.com/facebookresearch/sam2.git'
can be found on Colab
So, python -m pip install git+https://github.com/facebookresearch/sam2.git
seems to work fine.