Ubuntu: How to link a binary

Vivek picture Vivek · Jan 5, 2011 · Viewed 28.6k times · Source

I have a C++ code. I compiled it and I now have the binary xyz. Now everytime I need to execute the binary, I had to switch to the corresponding directory to execute it using ./xyz But how do I run the binary using a command say xyz from anywhere. How do I link this binary to a command in ubuntu. I currently use Ubuntu 10.10

Answer

unutbu picture unutbu · Jan 5, 2011

Ubuntu sets your PATH environment variable to include ~/bin. So the easiest way to make xyz executable from anywhere is move xyz to ~/bin, or to make a symlink from ~/bin to the xyz's directory:

ln -s /path/to/xyz/directory/ ~/bin

Or, you could add /path/to/xyz/directory/ to your PATH environment variable.