Suppose I installed a Debian package using the Ubuntu Software Center, and then suppose I wish to install the same program by compiling it from source. Then can I simply proceed by installing the same program compiling from source? Will this replace the previous version installed via deb package?
Debian packages generally install the binaries and libraries in /usr/bin/ and /usr/lib directories. Whereas when you compile the softwares from source, you are able to specify the prefix for the directories in which you want to install it. In general, the /usr/local/bin/ and /usr/local/lib directories are default in standard gnu softwares / foss (sort of de-facto standard). You can compile the softwares by specifying the prefix while running configure command. e.g. Say you want to install the software in /usr/local/ prefix, you should run these commands:
You can specify --prefix to be any directory e.g. it can be ~/.local/ or any other directory for that matter.
Now you have two binaries with the same name but in different directories installed. Which one of these will be used when you invoke the command (binary file) name, depends on the PATH variable of your shell. If the directory you installed the software is before the standard /usr/bin/ directory in the PATH variable value, it'll be run and debian one'll not be run. Check the PATH variable by running
echo $PATH
in terminal.