"cmake --version" points to /usr/bin/cmake while "which cmake" points to /usr/local/bin
In bash you can use hash -r
so that it forgets all remembered locations of previously executed commands.
It turns out I need to exit out of shell for the effect to take place. Once I start a new shell terminal cmake --version worked.