I have downloaded tdm64-gcc-5.1.0-2 and want to update but I don't know how to remove the previous version.
If you used an installer, TDM-GCC will be listed under Control Panel\Programs\Programs and Features and can be removed normally from there.
However, since you believe it is possible that an older version may have been included with Code::Blocks, you may wish to uninstall your current version of that program and choose a version that doesn't bundle TDM-GCC. On the Code::Blocks downloads page, the first three options (the ones that do not include
mingw in the file name) are the ones you are looking for.
That said, in either case, uninstalling isn't mandatory.
For the command line, you can simply edit your Window PATH/Path variables (Control Panel\System and Security\System → Advanced system settings -> Environment Variables...). You can remove any references to your previous installation of TDM-GCC and add any necessary entries for your new installation.
Likewise, many IDEs allow you to specify the exact location of the compiler components you wish to use (which likely makes having TDM-GCC registered at the command line less important).
For Code::Blocks specifically, these settings are located in Settings → Compiler... under the Toochain executables tab. Note that the locations of the items under Program Files should all be in your TDM-GCC installation
As a small suggestion, in case you are still completely clueless as to where TDM-GCC (or any other versions of
gcc.exe) might be located, doing a Windows search for
gcc.exe could be helpful.
Once installed correctly, your command line output should read:
gcc (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.`